Android和Facebook共享意图
我正在开发一个Android应用程序,并且有兴趣知道如何使用Android的共享意图从应用程序内更新应用程序用户的状态。
看过Facebook的SDK看起来这很容易做到,但我很想让用户通过常规的Share Intent弹出窗口来做到这一点? 在这里看到:

我尝试了通常的共享意图代码,但是这不再适用于Facebook。
public void invokeShare(Activity activity, String quote, String credit) {
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, activity.getString(R.string.share_subject));
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text");    
    activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.share_title)));
}
更新:完成更多挖掘工作后,它看起来好像是Facebook应用程序尚未解决的错误! (facebook bug)对于这段时间,看起来我只是不得不忍受负面的“共享不起作用!!!” 评论。 干杯Facebook:*(
  Facebook应用程序不处理EXTRA_SUBJECT或EXTRA_TEXT字段。 
这里是错误链接:https://developers.facebook.com/bugs/332619626816423
谢谢@billynomates:
  问题是,如果你把一个URL放在EXTRA_TEXT域中,它确实有效。  这就像他们故意删除任何文字。 
显然,Facebook不再(截至2014年)允许您自定义共享屏幕,无论您是打开sharer.php URL还是以更专业的方式使用Android意图。 例如看到这些答案:
  无论如何,使用简单的意图, 你仍然可以共享一个URL,但没有任何默认文本 ,因为billynomates评论。  (另外,如果您没有要共享的URL,只需启动带有空白“Write Post”(即状态更新)对话框的Facebook应用程序同样简单;请使用下面的代码,但不要使用EXTRA_TEXT 。) 
这是我发现的最好的解决方案,不涉及使用任何Facebook SDK。
如果安装了该代码,该代码将直接打开官方的Facebook应用程序,否则会退回到浏览器中打开sharer.php。 (这个问题中的大多数其他解决方案都带来了一个非常不理想的巨大“完整操作使用...”对话框 !)
String urlToShare = "https://stackoverflow.com/questions/7545254";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
// intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect!
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.katana")) {
        intent.setPackage(info.activityInfo.packageName);
        facebookAppFound = true;
        break;
    }
}
// As fallback, launch sharer.php in a browser
if (!facebookAppFound) {
    String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
startActivity(intent);
  (关于com.facebook.katana包名,请参阅MatheusJardimB的评论。) 
在安装了Facebook应用的Nexus 7(Android 4.4)上,结果如下所示:

通常的方法
创建你所要求的常用方法是简单地执行以下操作:
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, "The status update text");
    startActivity(Intent.createChooser(intent, "Dialog title text"));
这对我来说没有任何问题。
另一种方式(可能)
这样做的潜在问题在于,您还允许通过电子邮件,短信等方式发送消息。以下代码是我在应用程序中使用的,它允许用户向我发送电子邮件使用Gmail的邮件。 我猜你可以尝试改变它,使它只与Facebook一起工作。
我不确定它是如何响应任何错误或异常(我猜如果没有安装Facebook,会发生这种情况),因此您可能需要测试一下。
    try {
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        String[] recipients = new String[]{"e-mail address"};
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "E-mail subject");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "E-mail text");
        emailIntent.setType("plain/text"); // This is incorrect MIME, but Gmail is one of the only apps that responds to it - this might need to be replaced with text/plain for Facebook
        final PackageManager pm = getPackageManager();
        final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
        ResolveInfo best = null;
        for (final ResolveInfo info : matches)
            if (info.activityInfo.packageName.endsWith(".gm") ||
                    info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
                if (best != null)
                    emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
                startActivity(emailIntent);
    } catch (Exception e) {
        Toast.makeText(this, "Application not found", Toast.LENGTH_SHORT).show();
    }
