facebook 的 Android 共享意图 - 共享文本和链接 [英] Android share intent for facebook- share text AND link

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

问题描述

我正在尝试使用 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);
    }
}

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

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