Android分享意向为Facebook-共享文本和链接 [英] Android share intent for facebook- share text AND link

查看:144
本文介绍了Android分享意向为Facebook-共享文本和链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Android分享意向在Facebook上发布内容。看起来像这样:

I am trying to use the Android share intent to post something on facebook. It looks like this:

shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Free education for all! http://linkd.in/xU8mCc");
startActivity(shareIntent);

所以我的帖子都有 - 一些文本和一个链接。但是当消息发布在Facebook上时,它只有链接,没有消息。我尝试过各种附加功能,但没有任何作用。

So my post has both - some text and a link. But when the message is posted on facebook, it only has the link, no message. I tried various extras but nothing works.

任何人面临这个问题并解决了吗?我有Facebook应用程序版本1.8.1

Anyone faced this issue and solved it? I have facebook app version 1.8.1

编辑:我尝试删除链接,而Facebook应用程序不会收到我的消息(显示一个空白的消息要发布)但不是相反。所以看起来应用程序完全忽略任何纯文本消息。我很惊讶!这是fb应用程序中的一个主要错误,短信无法发布(有意图)?

I tried removing the link, and the facebook app does not take my message (shows a blank message to be posted), but not the other way round. So looks like the app is totally ignoring any plain text messages. I am spooked! Is this a major bug in the fb app that text messages can not be posted at all (with share intent)?

推荐答案

我只是构建了这个代码,它为我工作:

I just built this code and it's working for me:

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);
    }
}

这篇关于Android分享意向为Facebook-共享文本和链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆