I want to share multiple picture with single caption which is shown on one image not on all of them. But caption will show on every pic which is shared at one time.
Here is my code
private void pic_with_data() {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriArray);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Download this App");
shareIntent.setType("text/plain");
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(Intent.createChooser(shareIntent, "Share Image!"));
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
}
}
Use Intent.ACTION_SEND_MULTIPLE instead of Intent.ACTION_SEND.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/jpeg"); /* This example is sharing jpeg images. */
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);
Remember, Starting in API 24, sharing file URIs will cause a FileUriExposedException. To remedy this, you can either switch your compileSdkVersion to 23 or lower or you can use content URIs with a FileProvider.
I didn't had a chance to compile this but this should work
val files: ArrayList<Uri> = arrayListOf()
// add files here in `files` variable
startActivity(Intent(Intent.ACTION_GET_CONTENT)
.setType("image/*")
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files))
Related
I need to share 2 csv files I created in my app.
I was able to share one of them with the below code, but how to I pass 2 files to share?
for (File file : fileList) {
if (!file.exists()) {
Toast.makeText(ExcelExportActivity.this, "File doesn't exists", Toast.LENGTH_LONG).show();
return;
}
Uri uri = FileProvider.getUriForFile(ExcelExportActivity.this, "com.example.farmers.provider", file);
grantUriPermission(ExcelExportActivity.this.getPackageName(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
sharingIntent.setType("text/csv");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
}
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "my subject");
startActivity(Intent.createChooser(sharingIntent, "sharing with..."));
You will need to use Intent.ACTION_SEND_MULTIPLE instead of Intent.ACTION_SEND.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("text/csv");
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);
I'm working on share functionality
I 've a problem with Instagram Share
Here is my code :
I'm trying share "account" image which is stored in "drawable" folder.This is just an example
try {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.parse("android.resource://com.example.swathi.booklender/drawable/account");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
}catch (Exception e)
{
Toast.makeText(getActivity(),"No Activity available, install instagram",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
How to I get rid of this problem?
You can't share drawable directly
First create a file from drawable then share it
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
File image = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
startActivity(Intent.createChooser(shareIntent, "Share image via"));
Hi everyone I'm an android develeloper and in my app I need to share an image with a text by whatsapp, the problem is that Uri method doesn't work anymore. This is Uri method:
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.");
}
So is there any method different from this one?
hey guys i want to share image from server to whatsapp but its give an error image share failed can you tell me can i share image directly server to whatsapp what i am doing something wrong
this is my code
Intent shareIntent = new Intent();
Uri imageUri = Uri.parse("http://stacktoheap.com/images/stackoverflow.png"); // here is my selected url
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT, img_txt);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
}
help me friends
my answer is simple first download image from sever and then share image on whatsapp
try this code
String imagePath =Environment.getExternalStorageDirectory() + "your folderpath"+"imagename";
File f=new File(imagePath);
Uri uri = Uri.fromFile(f);
Intent share = new Intent(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.setType("image/jpg");
share.putExtra(Intent.EXTRA_TEXT,"your text"); //want share text with image
share.putExtra(Intent.EXTRA_STREAM, uri);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(share);
} catch (android.content.ActivityNotFoundException ex) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp")));
}
You are getting issue because you are sharing image and text both
Infact whatsapp doesn't allow to share image and text simultaneously, try either image only
Here i am sharing images from my app to whatsapp.but this code is working here only for mylist1[i] and not for mylist2[i] and mylist3[i]. As in my activity file there are 15 images in every 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"));
Take image array in mylist[] and use below code, then share image via 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"));
If I'm not wrong then for that you should use android.content.Intent.ACTION_SEND_MULTIPLE..Refer this link it will help you..
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);