Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share image and text through Whatsapp or Facebook

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.

like image 212
user2802764 Avatar asked Apr 15 '14 07:04

user2802764


People also ask

Can you share photos from Facebook to WhatsApp?

Steps to Send Picture or Message from Facebook to WhatsAppFrom your Android or iOS device, open the Facebook App. Now you may upload any image or text. You may also share a friend's public postings. After it has been uploaded, select the Share option.


1 Answers

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.");     } 
like image 177
Display name Avatar answered Sep 18 '22 00:09

Display name