在Facebook上分享多张照片

时间:2013-02-05 11:32:30

标签: android

我想在我的应用中分享多张照片。我可以使用脸谱图API上传一张照片,但如何分享多张照片

感谢名单。

2 个答案:

答案 0 :(得分:1)

Android不提供用于选择多个图片/图片或任何其他媒体类型的开箱即用的 Intent 。资料来源:https://stackoverflow.com/a/12919585/450534(我通常会把Mark Murphy的话作为福音,除非有人可以挑战它)

最接近的意图是ACTION_SEND_MULTIPLE.那个。但是,不适合你。

您需要创建一个自定义选择器,类似于Facebook在其自己的移动应用中所做的工作。

您将在此处获得一个完整功能示例,用于实现您自己的多个图像选择器:http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/

最后,要一次性将多个图像上传到Facebook,您需要发送Batch Requests

但肯定没有现成的解决方案来满足您的需求。结合以上所有,然后你会。但是我害怕没什么直白的。

答案 1 :(得分:0)

我设法使用意图在Facebook上分享多张照片。 变量“caminhos”是ArrayList<字符串>与您想要分享的图像的路径。

protected void share(String nameApp, String imagePath, String text) {
// TODO Auto-generated method stub

try {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    Intent share = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    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_MULTIPLE);
            targetedShare.setType("image/png"); // put here your mime
            // type
            if (info.activityInfo.packageName.toLowerCase().contains(
                    nameApp)
                    || info.activityInfo.name.toLowerCase().contains(
                            nameApp)) {
                targetedShare.putExtra(Intent.EXTRA_SUBJECT, text);
                targetedShare.putExtra(Intent.EXTRA_TEXT, text);
                ArrayList<Uri> files = new ArrayList<Uri>();
                for(int j= 0;j<caminhos.size();j++){
                    if(!caminhos.get(j).isEmpty()){
                        File file = new File(caminhos.get(j));
                        Uri uri = Uri.fromFile(file);
                        files.add(uri);
                    }
                }

                targetedShare.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
                        files);
                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);
    }
} catch (Exception e) {
}

}

相关问题