How to share images with my app in whatsapp?

Here I post images from my application to whatsapp.but, this code works here only for mylist1 [i], and not for mylist2 [i] and mylist3 [i]. Like my activity file, there are 15 images in each list. what to do?

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
Uri uri = Uri.parse("android.resource://com.example.drawcelebrities/"+mylist1[i]+mylist2[i]+mylist3[i]);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share via"));
+4
source share
3 answers

Take an array of images in mylist [] and use the code below, and then share them through whatsapp.

Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+mylist[i]);

Intent shareIntent = new Intent();
             shareIntent.setAction(Intent.ACTION_SEND);
             shareIntent.setType("image/*");
             shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
             startActivity(Intent.createChooser(shareIntent, "Share via"));
+2
source

If I'm not mistaken, then you should use for this android.content.Intent.ACTION_SEND_MULTIPLE.. Refer to this link , this will help you.

0
source
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/jpeg");
ArrayList<Uri> files = new ArrayList<Uri>();
for(String path : filesToSend /* List of the files you want to send */) {
File file = new File(path);
 Uri uri = Uri.fromFile(file);
files.add(uri);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);
-1
source

Source: https://habr.com/ru/post/1533110/


All Articles