从Android应用程序在Facebook上分享文本

时间:2014-11-05 06:55:37

标签: android eclipse facebook share facebook-share

您好我需要将我的应用程序中的文字分享给Facebook我试过这段代码

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, DESCRIPTION);
        sharingIntent.putExtra(Intent.EXTRA_TEXT, DESCRIPTION);
        PackageManager packManager = getPackageManager();
        List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(sharingIntent,        PackageManager.MATCH_DEFAULT_ONLY);

        boolean resolved = false;
        for(ResolveInfo resolveInfo: resolvedInfoList){
            if(resolveInfo.activityInfo.packageName.startsWith("com.facebook.katana")){
                sharingIntent.setClassName(
                    resolveInfo.activityInfo.packageName, 
                    resolveInfo.activityInfo.name );
                resolved = true;
                break;
            }
        }
        if(resolved){
            startActivity(sharingIntent);
        }else{

             android.app.AlertDialog.Builder alert  = new   AlertDialog.Builder(SingleItemView.this);
                alert.setTitle("Warning");
                alert.setMessage("Facebook App not found");
                alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int which) 
                    {
                        dialog.dismiss();

                    }
                });
                alert.show();
        } 

它通过已安装的Facebook打开Facebook帖子,但有空白帖子如何将我的文本传递给Facebook应用程序?

2 个答案:

答案 0 :(得分:3)

请尝试这种方式,希望这有助于您解决问题。

现在Facebook API不支持为用户预先填写邮件,如本政策所示:https://developers.facebook.com/policy/

查看此讨论:https://developers.facebook.com/bugs/332619626816423

答案 1 :(得分:0)

据我所知,Facebook只允许共享链接。所以你的意图很好,但尝试共享一个http://链接。它共享该站点并允许用户对他们共享的链接发表评论。