Ashish Jani
Ashish Jani

Reputation: 295

Share multiple photos on facebook

I want in my app to share multiple photos. I am able to upload one photo using facebook graph API but how can I share multiple photos

Thanx.

Upvotes: 0

Views: 2809

Answers (2)

Gabriel Kaffka
Gabriel Kaffka

Reputation: 1039

I managed to share multiple photos in Facebook using intents. The variable "caminhos" is an ArrayList < String > with the paths of the images you want to share.

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) {
}

}

Upvotes: 0

Siddharth Lele
Siddharth Lele

Reputation: 27748

Android does not provide an out-of-the-box Intent for selecting multiple images/pictures, or any other media type. Source: https://stackoverflow.com/a/12919585/450534 (And I usually will take Mark Murphy's word as Gospel unless someone can challenge it)

The closest Intent is the ACTION_SEND_MULTIPLE. That. however, is not an option for you.

You will need to create a custom selector similar to how Facebook does in it's own mobile app.

You will get a full functioning example for implementing your own multiple image selector here: http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/

And finally, to upload multiple image to Facebook in one go, you will need to send Batch Requests.

But there certainly is no ready made solution for what you are looking for for. Combine all the above, and then you will. But nothing straightforward I'm afraid.

Upvotes: 1

Related Questions