Share image and text through Whatsapp or Facebook

user2802764 picture user2802764 · Apr 15, 2014 · Viewed 77.2k times · Source

I have in my app a share button and i want to share an image and a text at the same time. In GMail it works fine but in WhatsApp, only the image is sent and in Facebook the app crashes.

The code i use to share is this:

Intent shareIntent = new Intent(Intent.ACTION_SEND);  
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Message");         

Uri uri = Uri.parse("android.resource://" + getPackageName() + "/drawable/ford_focus_2014");
     try {
        InputStream stream = getContentResolver().openInputStream(uri);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

If I use "shareIntent.setType("*/ *")" Facebook and WhatsApp crashes.

Is there some way to do this? Maybe sent two messages by separate at the same time (WhatsApp).

Thanks in advance.

Answer

Display name picture Display name · Nov 6, 2014

Currently Whatsapp supports Image and Text sharing at the same time. (Nov 2014).

Here is an example of how to do this:

    /**
     * Show share dialog BOTH image and text
     */
    Uri imageUri = Uri.parse(pictureFile.getAbsolutePath());
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    //Target whatsapp:
    shareIntent.setPackage("com.whatsapp");
    //Add text and then Image URI
    shareIntent.putExtra(Intent.EXTRA_TEXT, picture_text);
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    shareIntent.setType("image/jpeg");
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    try {
        startActivity(shareIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        ToastHelper.MakeShortText("Whatsapp have not been installed.");
    }