有同样的问题,想要检测 facebook 共享选项并采用不同的逻辑路径(主要是因为通过常规 android 共享的 facebook 共享是有限的)
我的解决方案
public void shareIt(View view){
//sharing implementation
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "string of text " + txt_var + " more text! Get the app at http://someapp.com";
PackageManager pm = view.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(sharingIntent, 0);
for(final ResolveInfo app : activityList) {
String packageName = app.activityInfo.packageName;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "share");
if(TextUtils.equals(packageName, "com.facebook.katana")){
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://someurl.com");
} else {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
}
targetedShareIntent.setPackage(packageName);
targetedShareIntents.add(targetedShareIntent);
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Share Idea");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
这在此 Q 和 A 中列出
根据他们选择共享的方法来分支 Android Share Intent 额外内容