【问题标题】:intent share facebook - Android意图分享 facebook - Android
【发布时间】:2017-05-10 05:43:13
【问题描述】:

我想将 android 活动中的图像分享到 facebook messenger 应用程序,该应用程序已在我的设备中打开并驻留在 android 设备的最近任务中。

我正在使用以下代码共享图像,但它正在 Messenger '单独共享'中打开一个新活动,但我想将其共享到已打开的聊天中。

String mimeType = "image/*";

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);

activity.startActivityForResult(shareIntent, SHARE_TO_MESSENGER_REQUEST_CODE);

【问题讨论】:

    标签: android facebook


    【解决方案1】:

    Facebook 已限制通过帖子分享文本。它将要么支持有效的 URL 链接共享图像共享。所以我发布了从https://stackoverflow.com/a/22994833/8331006引用的代码

    private void shareAppLinkViaFacebook(String urlToShare) {
        try {
            Intent intent1 = new Intent();
            intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
            intent1.setAction("android.intent.action.SEND");
            intent1.setType("text/plain");
            intent1.putExtra("android.intent.extra.TEXT", urlToShare);
            startActivity(intent1);
        } catch (Exception e) {
            // If we failed (not native FB app installed), try share through SEND
            String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
            startActivity(intent);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多