user1784588
user1784588

Reputation: 99

share image with caption to social media using intent android

I am facing a small problem in sharing image using intent. This is my case, I want to share an image with caption (caption may be link or text), when i used the below code

Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");

            shareIntent.setType("image/*");

            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.whatsapp_promotion);
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);

            String path = MediaStore.Images.Media.insertImage(
                    getContentResolver(), bitmap, null, null);
            Uri uri = Uri.parse(path);
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
            shareIntent
                    .putExtra(
                            Intent.EXTRA_TEXT,
                            "**my message with URL **");

            startActivity(Intent.createChooser(shareIntent, "Share Via..."));

I can share with hangout, whatsapp, twitter etc., but am not able to share with facebook. So what i decided is one image with the caption that's it, that can be share in whatsapp, hangout, facebook etc.,

How to do this, please help me out

Thanks in advance

Upvotes: 0

Views: 1469

Answers (3)

vaibhav
vaibhav

Reputation: 816

Here is the documentation to share photos on facebook https://developers.facebook.com/docs/sharing/android#photos

Here is the code snippet to build content for your image

Bitmap image = ...
SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(image)
        .setCaption("Enter your caption")
        .build();
SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .build();

And then to share ShareDialog.show(YourActivity.this, content);

Complete documentation for sharing on facebook here : https://developers.facebook.com/docs/sharing/android

Upvotes: 0

SuperFrog
SuperFrog

Reputation: 7674

You need the Facebook sdk, and then you can do this:

    SharePhoto photo = new SharePhoto.Builder().setBitmap(
            getYourBitmapMethod()).build();

    SharePhotoContent content = new SharePhotoContent.Builder()
            .addPhoto(photo).setRef("This is a test").build();

    ShareDialog.show(YourActivity.this, content);

Upvotes: 0

Jas
Jas

Reputation: 3212

You cannot share image and text to Facebook through Intent.For that,you have to use Facebook API.

Upvotes: 1

Related Questions