I have been using the following code to share to facebook and any other apps:
private void initShareIntent(String type, String title, String link) {
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType(Constants.MIMETYPE_TEXT_PLAIN);
List<ResolveInfo> resInfo = getContext().getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(type) ||
info.activityInfo.name.toLowerCase().contains(type)) {
if (title != null && link != null) {
share.putExtra(Intent.EXTRA_SUBJECT, unescapeTitle(title));
share.putExtra(Intent.EXTRA_TEXT, link.replace(Constants.HTTP_SCHEME, Constants.HTTPS_SCHEME));
share.setPackage(info.activityInfo.packageName);
}
found = true;
break;
}
}
if (!found)
return;
getContext().startActivity(share);
}
}
I provide the word facebook as the type variable. For the longest time the code was working fine and was opening the facebook share dialog.
Now, however, the same code opens messenger instead to initiate the share. Is there a way to force it to open facebook and not messenger?