Android 在Facebook上共享文本/图像

Android 在Facebook上共享文本/图像,android,facebook,image,text,share,Android,Facebook,Image,Text,Share,我是android编程新手,在分享内容方面有一些问题。 我做了一个涉及测试的android应用程序。在上一个活动中,我想提供一个通过shareintent共享用户结果的机会,这里是一个代码框架: display= (TextView) findViewById (R.id.tvDisplay); display.setText("Well Done, your score is" + score ); //score is an int sharebutton= (Bu

我是android编程新手,在分享内容方面有一些问题。 我做了一个涉及测试的android应用程序。在上一个活动中,我想提供一个通过shareintent共享用户结果的机会,这里是一个代码框架:

    display=  (TextView) findViewById (R.id.tvDisplay);
    display.setText("Well Done, your score is" + score ); //score is an int
    sharebutton= (Button)findViewById(R.id.sharebutton);
    sharebutton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            results = display.getText().toString();
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_TEXT,"My score in the test is" + results);
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, "TEST");
            startActivity(Intent.createChooser(shareIntent, "Share.."));
        }
    });
问题是,当我点击按钮时,我可以在所有共享工具电子邮件、wapp等中共享确切的文本,但不能通过Facebook。为什么? 我试图允许在FB墙上张贴图像和文本,但我无法给出可绘制文件夹中图像的确切路径。
谢谢您的建议。

首先在SD卡中存储图像,然后在facebook上共享图像

File filePath = new File(Environment
                    .getExternalStorageDirectory(),
                    "/foldername/imagename.jpg");
            // share("facebook", filePath.toString());
            System.out.println(filePath);
            List<Intent> targetedShareIntents = new ArrayList<Intent>();
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/jpeg");
            List<ResolveInfo> resInfo = getActivity().getPackageManager()
                    .queryIntentActivities(share, 0);
            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    Intent targetedShare = new Intent(
                            android.content.Intent.ACTION_SEND);
                    targetedShare.setType("image/jpeg"); // put here your
                                                            // mime
                    // type
                    if (info.activityInfo.packageName.toLowerCase()
                            .contains("facebook")
                            || info.activityInfo.name.toLowerCase()
                                    .contains("facebook")) {
                        targetedShare.putExtra(Intent.EXTRA_SUBJECT,
                                "Sample Photo");
                        targetedShare.putExtra(Intent.EXTRA_TEXT,
                                "This photo is created by App Name");
                        targetedShare.putExtra(Intent.EXTRA_STREAM,
                                Uri.fromFile(filePath));
                        targetedShare
                                .setPackage(info.activityInfo.packageName);
                        targetedShareIntents.add(targetedShare);
                    }
                }
                Intent chooserIntent = Intent.createChooser(
                        targetedShareIntents.remove(0),
                        "Select app to share");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetedShareIntents.toArray(new Parcelable[] {}));
                startActivity(chooserIntent);
            }

这取决于Facebook应用程序是否通过intent接受文本,我知道他们接受图像和位图文件,但对于文本,他们不接受。我之前已经在自己的一个项目中尝试过,但无法通过intent提供文本

The Facebook application does not handle either the EXTRA_SUBJECT or EXTRA_TEXT fields.

我已经回答了这个问题。如果你需要参考资料,也许你可以按照这个回答。

看看这个:嗨,我试过你的尝试,但没有成功。当我点击FB图标时,我只能在我的FB墙上发布一些东西,而不能发布图片。我编写了文件myFile=newfileenvironment.getExternalStorageDirectory+/ic_launcher.png;-我试着发布启动器图标来测试它。它不起作用。也有类似的问题。点击按钮后,我可以在FB墙上书写,但我无法共享图像或文本。也许我不理解你的答案,但你告诉我,无法通过FB共享文本或图像?可以共享图像,但不能共享文本