嗨,我需要将我的应用程序中的文本分享到 Facebook 我试过这段代码
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, DESCRIPTION);
sharingIntent.putExtra(Intent.EXTRA_TEXT, DESCRIPTION);
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for(ResolveInfo resolveInfo: resolvedInfoList){
if(resolveInfo.activityInfo.packageName.startsWith("com.facebook.katana")){
sharingIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name );
resolved = true;
break;
}
}
if(resolved){
startActivity(sharingIntent);
}else{
android.app.AlertDialog.Builder alert = new AlertDialog.Builder(SingleItemView.this);
alert.setTitle("Warning");
alert.setMessage("Facebook App not found");
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which)
{
dialog.dismiss();
}
});
alert.show();
}
它通过安装的 Facebook 打开 Facebook 帖子,但使用空白帖子我如何将我的文本传递给 Facebook 应用程序?