【问题标题】:Android Share intent - facebookAndroid 分享意图 - facebook
【发布时间】:2013-04-25 08:01:03
【问题描述】:

我想和我的朋友分享一些东西。所以我更喜欢android分享意图。 我用过,

Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "my share text");
startActivity(Intent.createChooser(i, "share via"));  

这显示了可用应用程序的列表,例如 Facebook、Twitter、Gmail、Message、Skype.. e.t.c.. 如果我按某种意义上的推特,上面的文本“我的分享文本”会显示在推文文本框中。 但如果我选择 Facebook,状态消息不会显示。 我想以编程方式设置状态消息。

我怎样才能做到这一点?

【问题讨论】:

标签: android facebook share


【解决方案1】:

Facebook SDK 有这个错误,我知道这很烦人。但是如果你将一个链接(并且只有一个链接)设置为“我的分享文字”,它就会出现在 facebook 分享框中。

【讨论】:

  • 这不是错误,Facebook 希望您创建与您的 Android 应用程序高度集成的 Facebook 应用程序。因此,他们希望您的应用程序对 Facebook 具有真正特殊的行为,而不仅仅是分享一些文本。
  • 为什么它最初支持它
  • 谢谢它真的帮助了我,链接是我想要的全部
【解决方案2】:

我刚刚构建了这段代码,它对我有用:

private void shareAppLinkViaFacebook() {
    String urlToShare = "YOUR_URL";

    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
        Intent intent = new Intent(Intent.ACTION_SEND);
        String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
        startActivity(intent);
    }
}

【讨论】:

    【解决方案3】:

    Facebook 不允许在状态框中预先填充文本,例如 twitter。但是我们可以将带有 url 的文本传递给 Facebook。它出现在状态框下方。检查下面的代码。

    注意:使用 Facebook SDK 分享[推荐]。

    通过意图进行本机分享

     Intent shareIntent= new Intent();
     shareIntent.setAction(Intent.ACTION_SEND);
     shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
     shareIntent.setType("text/plain");
     shareIntent.setPackage("com.facebook.katana");
     startActivity(shareIntent); 
    

    通过 Facebook SDK 分享

    ShareDialog shareDialog;
    
    // Sharing in Facebook using the SDK
    FacebookSdk.sdkInitialize(this);
    shareDialog = new ShareDialog(this);
    
    String title = "Demo Title";
    String URL = "http://www.google.com";
    
    ShareLinkContent linkContent = new ShareLinkContent.Builder()
                    .setContentTitle(title).setContentDescription(URL)
                    .setContentUrl(Uri.parse(URL)).build();
    
    shareDialog.show(linkContent);
    

    查看下面的链接以供参考。

    Link 1

    如有疑问或澄清,请告诉我。

    【讨论】:

    • 请将问题标记为重复问题,而不是使用答案。
    • 尊敬的评论者,很抱歉这个错误。检查我的更新答案。
    猜你喜欢
    • 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
    相关资源
    最近更新 更多