2

它在电子邮件和 Twitter 中共享图像和文本,但在 facebook 文本中未显示。Is it possible to share text to facebook using intent?.

请为此提供帮助。

private void share(String nameApp, String imagePath) 
{
    try
    {
        List<Intent> targetedShareIntents = new ArrayList<Intent>();
        Intent share = new Intent(android.content.Intent.ACTION_SEND);
        share.setType("image/jpeg");
        List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
        if (!resInfo.isEmpty()){
            for (ResolveInfo info : resInfo) {
                Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
                targetedShare.setType("image/jpeg"); // put here your mime type
                if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
                    targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Virtual Mirror Photo");
                    targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by Virtual Mirror App.\n\nInfoshore Team");
                    targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)) );
                    targetedShare.setPackage(info.activityInfo.packageName);
                    targetedShareIntents.add(targetedShare);
                }
            }
            Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
            startActivity(chooserIntent);
        }
    }
    catch(Exception e){
    }
}
4

2 回答 2

1

根据 Facebook 的平台政策,我们无法使用 Intent.EXTRA_TEXT 预先填写分享对话框。它通常被认为是一个错误,但根据此处提交的错误报告以及此处 Facebook 明确提到情况并非如此(这不是错误)。

我发现我们无法为使用 Intents 上传的照片添加标题。我们能做到这一点的唯一方法是将Facebook SDK集成到您的应用程序中,然后带有文本标题的照片将在 Facebook 墙上共享。

于 2013-03-03T15:04:20.593 回答
0

是的,可以使用 Facebook 共享文本

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Content to share");
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
    if ((app.activityInfo.name).contains("facebook")) {
        final ActivityInfo activity = app.activityInfo;
        final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
        shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |             Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        shareIntent.setComponent(name);
        v.getContext().startActivity(shareIntent);
        break;
   }
}

参考StackOverflow

于 2012-11-12T07:11:13.530 回答