react-native-social-share
react-native-social-share copied to clipboard
Android tweet share uses the webbrowser in the emulator (Not an error, Explanation inside)
Hi there, Firstly I'd like to say that I really like the library you guys have built. The main problem I'm having is that when I click "share on twitter", it opens up the chrome browser on my emulator and sets up the tweet over there. On the README, you guys have it showing a popup within the app where you can send the tweet. Is this just because I'm on an Android emulator, or am I missing something? Please help. Thank you.
Hi @pakicoder123 Thank you, I am happy you like it 👍
I didn't code the Android part myself, but looking through the files it seems to me that it is just a fallback in case there is no Twitter app installed, so yes it is because you are in the emulator.
See: https://github.com/doefler/react-native-social-share/blob/master/android/src/main/java/com/barefootcoders/android/react/KDSocialShare/KDSocialShareModule.java
if (doesPackageExist("com.twitter.android")) {
try {
tweetViaTwitterComposerClass(shareText);
} catch (Exception ex1) {
try {
tweetViaTwitterDefaultClass(shareText);
} catch (Exception ex2) {
tweetViaWebPopup(shareText);
}
}
} else {
tweetViaWebPopup(shareText);
}
private void tweetViaWebPopup(String shareText) throws Exception {
String tweetUrl = "https://twitter.com/intent/tweet?text=" + shareText;
Uri uri = Uri.parse(tweetUrl);
Intent shareIntent = new Intent(Intent.ACTION_VIEW, uri);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
reactContext.startActivity(shareIntent);
}
Hi, thank you for the quick reply! And that would make sense, I looked at those lines earlier but now it makes sense. If it wouldn't trouble you too much I would really appreciate if you could answer just one more question. Would you by any chance know how to post images with a status to twitter using the twitter API? I've been working on this for nearly 10+ hours every day and I'm still a novice at React Native so I would appreciate it, if not I completely understand and am grateful for your help. Thank you again
@pakicoder123 - definitely agreed. If you get it working to the point of the browser opening you're all set, once it's on a device with the Twitter app it works.
I should probably clarify, I mean is there any way to stay in the app and post a status with an image, without needing the twitter app downloaded as well?
You are welcome @pakicoder123 No, I haven't tried using the Twitter API in React Native for Android myself. What in particular are you finding difficult?
Hey @angusmccloud
If you get it working to the point of the browser opening you're all set, once it's on a device with the Twitter app it works.
Maybe we should add that as a side note in the README to new people coding for Android. What do you think?
@doefler Apologies in advance for the lengthiness of this response, I also want you to know that I greatly appreciate your time, I've been stuck without help for quite a while on this:
So basically I want a user to be able to click a share button and have my app post a tweet with an image I pull from our backend, saying something like "hey everyone, check this out!". But I want it all to be done in-app, with no need for installation of other apps and without the user ever leaving my app. Your library is great but with the caveat that the user will need to either install the twitter app or be temporarily taken into their chrome browser. That's why I was thinking maybe a workaround to this roadblock would be to use a twitter api post request, but I've scoured the webs and the only thing I found was "react-native-twitter", which is capable of posting a status with an image: the only problem is that the image needs to be pulled from the device's camera roll, apparently that's a special type of image object in react native. Please let me know if you could offer any insight into this problem
@pakicoder123
I have no experience coding for Android so can't really give any educated advice. Also saw "react-native-twitter", which seems like an option.
My initial thoughts:
- Could you download the file before posting and then access the file using a local path?
- Could you have the file already be in the app and then use it?
- Check out https://facebook.github.io/react-native/docs/images.html
Thank you for all your advice, will definitely read up more on that link and try out your suggestions. My sincere appreciation for your talented coding, time, and help. Best regards!
@pakicoder123
You are welcome, let's keep it open in case other people are wondering about the web popup.
Sounds fine by me, I'm new to github issues too lol. Hope other people find what they're looking for too, have a good day
Same here 😄 You too have a nice day.