Simply want to share a dynamic text string + the URL to the app. The native Android share intent is setup correctly, and works perfect with Twitter, Gmail, etc. But, as many will guess, it does not work with Facebook. Appearantly because Facebook will not accept text in the intent.EXTRA_TEXT
field, only a single URL.
Well, my question to y'all is: is there a way to branch off the share intent extras depending on which method they choose to share? for example, if they share via gmail or Twitter, use the existing String + URL
(the desired option) EXTRA_TEXT
, but if they choose to share via Facebook, only use a URL as the EXTRA_TEXT
.
Not really wanting to implement the Facebook Android SDK for such a simple task that is built-in natively in Android.
Appreciate your time and advice.
Tried something like this, but it obviously fails because its only checking if the sharing option exists (when share pops up, not after they click a share method), it doesn't respond when they choose a method.
String shareBody = "app string text " + act_txt + " more text! Get the app at http://www.appurl.com";
PackageManager pm = view.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(sharingIntent, 0);
for(final ResolveInfo app : activityList) {
Log.i(TAG, "app.actinfo.name: " + app.activityInfo.name);
//if((app.activityInfo.name).contains("facebook")) {
if("com.facebook.katana.ShareLinkActivity".equals(app.activityInfo.name)) {
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://www.appurl.com");
startActivity(Intent.createChooser(sharingIntent, "Share idea"));
break;
} else {
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "app name");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share"));
break;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…