Share Image and Text to Facebook on android

Iain Smith picture Iain Smith · May 21, 2014 · Viewed 29.9k times · Source

What is the correct way to share an image and text to Facebook in android? e.g. picture with pre-populated text.

I realise that this is not possible from the native Android share intent as described here. As it can only take an image or a link not both.

Also I have tried using the facebook-sdk-3.14 with:

    FacebookDialog.ShareDialogBuilder 

but I now realise this is for sharing links only.

I have also tried with:

    createShareDialogBuilderForPhoto() 

but this is for sharing images only.

Is there something I am missing in the sdk? I am guessing it is not possible from FacebookDialog?

Will I need to go the route of creating my own app in facebook and my own open graph action? Ideally I am looking to not have a login button.

I have also seen similar questions but most are about the share intent or if it is the sdk it at least a year out of date and the solution is some thing similar to this:

    Bundle parameters = new Bundle();
            parameters.putString("message", category_item_name_desc.getText().toString());
            parameters.putString("picture", categoryItemsModel.getImageUrl());
            parameters.putString("caption", txtDescription_desc.getText().toString());
            facebook.request("/me/feed", parameters, "POST");

Tried it through the Feed Dialog (WebDialog) but im getting a "error (#324) requires upload file", Any help would be great.

Answer

Deepshikha Puri picture Deepshikha Puri · Jun 24, 2015

You can share your image on facebook, Twitter, and Gmail:

Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);

Intent share = new Intent(Intent.ACTION_SEND);

share.setType(“image/jpeg”);

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, “Title”, null);
Uri imageUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, “Select”));