在Facebook上通过Intent分享文本而不使用Facebook sdk

问题描述 投票:29回答:7

由于Facebook不允许通过Intent共享文本,除非我们使用Facebook sdk,我正在寻找实现这一目标的方法。

我可以想到我可以使用的3个黑客:

1)由于Facebook允许图像共享,我可以生成一个Bitmap,共享文本绘制到它上面并使用Intent分享图像。

2)Facebook允许共享URL,在分享时它还会显示页面的Head。我可以在我的服务器上托管一个专用页面并将值作为参数传递到url中,并使用它生成Head。(我没有使用php的经验,但我想这是可能的)

3)将文本复制到剪贴板并通知用户。

要么

使用所有3的组合。

任何人都可以建议我更好的方式在Facebook上分享我的内容,而不使用Facebook sdk?

提前致谢。

android facebook android-intent
7个回答
46
投票

你无法使用android shareIntent在Facebook上单独分享文本。

只有通过Facebook SDK才能使用共享链接功能。

如果有图像,Facebook只会忽略意图中的额外文本。您可以共享图像,但不允许您共享文本内容。

不幸的是,Facebook共享意图只能使用带有前缀http://的单个URL,而不会添加其他文本消息。实际上facebook删除了文本内容,只允许URL / Link。它是由设计,我们无法控制它。

这会奏效

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
startActivity(Intent.createChooser(sharingIntent, "Share via"));

这不行。

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Share Text from App");
startActivity(Intent.createChooser(sharingIntent, "Share via"));

只有您可以在Facebook上分享文本的方法是使用Facebook SDK。

参考链接

Android share intent for facebook- share text AND link

Unable to share text with a link through Android Share Intent

Android and Facebook share intent


4
投票

使用此功能,我希望它会有所帮助

public static void share(Context context, String text, String subject, String title, String dialogHeaderText) {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    intent.putExtra(Intent.EXTRA_TITLE, title);
    context.startActivity(Intent.createChooser(intent, dialogHeaderText));
}

4
投票

首先,为了在FB上共享文本,你必须使用FB SDK。

没有FB SDK更好的选择是去一个带有“OG”数据的专用网站,它将自动解决。这样,您可以在需要更改时更改OG数据。

我建议你去找你的黑客号码2.但是,通过这种方法,FB允许用户点击链接并重定向到网站,你可以尝试根据你的要求处理这个。

我希望你能澄清一下。

有关OG的详细信息,请查看此Open Graph details


3
投票

此代码允许您仅在Facebook上粘贴您的内容。 id做的是获取手机中存在的所有应用的列表,然后找到打开然后打开的Facebook应用程序(如果已经存在)

        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text to be shared");
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
        for (final ResolveInfo app : activityList) {
            if ((app.activityInfo.name).contains("facebook")) {
                final ActivityInfo activity = app.activityInfo;
                final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                shareIntent.setComponent(name);
                startActivity(shareIntent);
                break;
           }
        }

3
投票

检查一下:

Intent share=new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "Some text you would like to share...");
share.setPackage("com.facebook.katana"); //Facebook App package
startActivity(Intent.createChooser(share, "Title of the dialog the system will open"));

这个代码你不需要facebook SDK ......

为了增强您的用户体验,您可以检查是否安装了Facebook App(或FacebookLite App)软件...


0
投票

当您使用本机意图时,如果用户使用意图中的数据,则由用户共享的应用程序决定。

这是一个已知的错误,Facebook已将此错误列入愿望清单。也许他们并没有试图修复它。这是故意让人们使用我认为的FB SDK。请参考此链接http://forum.developers.facebook.net/viewtopic.php?id=93900和这个post

http://forum.developers.facebook.net/viewtopic.php?id=93900


-1
投票

如果您不介意呈现其他共享选项,您可以使用常规共享意图与选择器,因为如果启用Facebook,Facebook将成为共享选项之一。

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, "Choose sharing method"));
© www.soinside.com 2019 - 2024. All rights reserved.