用标题,文字和链接填充facebook分享项目(Android)

时间:2014-09-19 09:28:00

标签: android facebook share

我试图在facebook上发布一个带有本机android共享功能的链接。我发现我无法为链接设置消息。但现在我想设置标题,消息和网址。

enter image description here

我想在红色方块中设置项目。由于用户政策,我已经发现我无法设置测试。

一些代码:

Intent shareIntent = new Intent();

shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TITLE, title);
shareIntent.putExtra(Intent.EXTRA_TEXT, title + "\n\n" + contentLink);
shareIntent.setType("text/plain");

return shareIntent;

这是我此时的代码,但这并没有将项目设置为红色方块。

2 个答案:

答案 0 :(得分:5)

文字分享 使用Android Intent Share for Facebook,您无法共享预先填充的文本。由于平台政策,这被Facebook本身阻止。结账部分2.3见下面的linl

https://developers.facebook.com/policy

链接分享 您可以分享链接。 Facebook将自动获取链接元数据。即图像,元标题和元描述。

图片分享 用户图像可以共享。这意味着您可以共享存储在设备上的图像。您无法在不保存的情况下直接与应用分享图片。作为黑客,您可以将图像保存在设备上,共享和删除图像(如果您不希望图像显示在用户的图库中)。

答案 1 :(得分:1)

使用此代码仅共享链接。 Facebook将自动获取链接元数据。即图像,元标题和元描述。

String urlToShare = "--------URL-------";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);

// See if official Facebook app is found
boolean facebookAppFound = false;
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) 
{
 if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")) 
 {
  intent.setPackage(info.activityInfo.packageName);
                    facebookAppFound = true;
                    break;
 }
}


if (!facebookAppFound) 
{
 String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
 intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
startActivity(intent);