android - 确定用户是否选择 Facebook 作为社交分享选项

标签 android facebook

我正在尝试设置社交分享。当我选择共享时,通过显示所有可用选项,它工作正常。但是无论如何我可以检查用户是否选择“Facebook”作为他们共享的方法,因为我想在发生这种情况时触发相关的 facebok sdk 相关代码。与其他共享选项不同,如果我不采用他们的 SDK 路线,Facebook 似乎对可以发布的内容有限制。

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if(id == R.id.social_share){
            //working - this opens up available sharing options on device.
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(android.content.Intent.EXTRA_SUBJECT, "A Title"); 
            i.putExtra(Intent.EXTRA_TEXT, "This is content... ");
            startActivity(i.createChooser(i, "Share"));

            //I want to use this code if facebook is selected.
            if (ShareDialog.canShow(ShareLinkContent.class)) {
                ShareLinkContent linkContent = new ShareLinkContent.Builder()
                        .setContentTitle("Hello Facebook")
                        .setContentDescription(
                                "The 'Hello Facebook' sample  showcases simple Facebook integration")
                        .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
                        .build();
                        .setImageUrl(Uri.parse("http://....."))
                shareDialog.show(linkContent);
            }
        }
        return true;
    } 

最佳答案

没有直接的方法来识别使用 ACTION_SEND Intent 选择了哪个应用。您将需要编写一个自定义应用程序选择器对话框来确定用户选择哪一个。检查this post查看其他用户作为类似问题的答案所写的一些内容。

关于android - 确定用户是否选择 Facebook 作为社交分享选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34637801/

相关文章:

android - 如何在一屏中使用两个ListView?

javascript - 如何在facebook邀请API上获取受邀用户信息

facebook - 将 Facebook 事件目标与洞察行动类型相匹配

facebook - 如何清除 Facebook 的图像缓存

android - 最新的 studio 3.6 中未生成数据绑定(bind)类

来自 Google I/O 的 Android 内存泄漏示例

ios - Facebook 登录和 FBSDKLoginKit Pod 之间的差异以及使用哪一个?

php - Heroku 1x 与 2x 网络测功机

android - 在相关布局中显示按钮

java - 如何从 Activity 中调用 fragment 方法?