Android and Facebook Share Intent

Android and Facebook share intent

The Facebook application does not handle either the EXTRA_SUBJECT or EXTRA_TEXT fields.

Here is bug link: https://developers.facebook.com/bugs/332619626816423

Thanks @billynomates:

The thing is, if you put a URL in the EXTRA_TEXT field, it does
work. It's like they're intentionally stripping out any text.

Android Intent directly to Facebook sharing?

Try the following code, now the intent will open Facebook directly.

List<Intent> targetedShareIntents = new ArrayList<Intent>();

Intent facebookIntent = getShareIntent("facebook", "subject", "text_or_url");
// subject may not work, but if you have a url place it in text_or_url
if(facebookIntent != null)
targetedShareIntents.add(facebookIntent);

Intent chooser = Intent.createChooser(targetedShareIntents.remove(0), "Delen");

chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));

startActivity(chooser);

// To precisely get the facebook intent use the following code

private Intent getShareIntent(String type, String subject, String text) 
{
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");

// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(share, 0);
System.out.println("resinfo: " + resInfo);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(type) ||
info.activityInfo.name.toLowerCase().contains(type) ) {
share.putExtra(Intent.EXTRA_SUBJECT, subject);
share.putExtra(Intent.EXTRA_TEXT, text);
share.setPackage(info.activityInfo.packageName);
found = true;
break;
}
}
if (!found)
return null;

return share;
}
return null;
}

Above code is extracted from this stackoverflow-post

Use Facebook sdk's ShareContent in share intent android

You need to add the Mime data type that the send intent is handling to get the appropriate activities returned:

share.setType("text/plain");

How to share text into facebook using default android sharing(intent)?

Try this...

 Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Share this app");
String shareMessage = "https://play.google.com/store";
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
startActivity(Intent.createChooser(shareIntent, "Choose the messenger to share this App"));


Related Topics



Leave a reply



Submit