Android ACTION_SEND_MULTIPLE with video and text - android

I'm trying to use the ACTION_SEND_MULTIPLE intent to share at the same time a video file and a text.
Now, this works in GMAIL (video in the attachments and text in the body of the mail), however I want to do the same in Whatsapp too, but it doesn't appear in the list of apps of the intent.
My code is the next:
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Descarga la app en...");
ArrayList<Uri> contenidos = new ArrayList<Uri>();
File file = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath()
+ "/Talking/"
+ nombreVideo
+ ".3gp");
Uri screenshotUri = Uri.fromFile(file);
contenidos.add(screenshotUri);
//sharingIntent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, contenidos);
sharingIntent.setType("video/3gpp");
startActivity(Intent.createChooser(sharingIntent, "Share video using"));
Thanks for your help.

Now your code gonna work due the new updates to whatsapp, before this didn't accept this kind of intent (ACTION_SEND_MULTIPLE) because it accepts only one file at a time.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("image/png");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.parse("file:///mnt/sdcard/UserImages/"+ ParseUser.getCurrentUser().getObjectId() + ".png"));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hello test");
startActivity(Intent.createChooser(shareIntent,"Share"));

This probably means Whatsapp does not support this kind of intent (ACTION_SEND_MULTIPLE).

Related

Share pdf file via whatsapp from my app on Android

I am try to send pdf file from my app to whatsapp, and here is the code,
but something missing!!
it opens whatsapp and i can choose a contact but it says "sharing failed"!
the code
String PLACEHOLDER = "file:///android_asset/QUOT_2016_10(test).pdf";
File f = new File(PLACEHOLDER);
Uri uri = Uri.fromFile(f);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_TEXT, "hi");
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("application/pdf");
activity.startActivity(share);
I figured out the problem, and here is the answer if somebody had the same issue. The problem was that I am trying to open the pdf from the asset folder which did n't work, and if would try to open the pdf from the download folder for example, it would work. Please refer to the the code below for the final correct way:
File outputFile = new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_DOWNLOADS), "ref Number from Quotation.pdf");
Uri uri = Uri.fromFile(outputFile);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/pdf");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("com.whatsapp");
activity.startActivity(share);
File outputPath= new File(Environment.getExternalStorageDirectory() + "/MyPdf/example.pdf");//change with your path
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("application/pdf");
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(),
getPackageName() + ".fileprovider", outputPath);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
startActivity(Intent.createChooser(shareIntent, "Share it"));
It's technically wrong, what if someone has WhatsApp business or want to share file on gmail then use this...
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, _text);
shareIntent.putExtra (Intent.EXTRA_STREAM, Uri.parse(_file));
startActivity(Intent.createChooser( shareIntent, "Share"));
In this u just have to add text and file
Text u attach will become subject in gmail and if you are sharing image on WhatsApp then text will become as image caption

Not able to share file with whitespace in name in android

I am not able to share audio file in whatsapp if there is any whitespace in the filename. But it works when sharing using email client. For filenames without spaces also it works fine. Below is the code which I am using
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
File F = new File(filePath);
F.setReadable(true, false);
Uri fileURI = Uri.fromFile(F);
Log.e("Share", "Share file url is " + fileURI);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Shared file");
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, fileURI);
I tried doing filePath.replace(" ", "\ "), not working.
What changes should be done to share the file?
This works when you trying to share with WhatsApp an audio file with whitespace:
String filePath = "file:///sdcard/Download/example attachment.mp3";
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(filePath));
shareIntent.setType("audio/*");
startActivity(Intent.createChooser(shareIntent, "Share audio file"));
I was able to share audio using same code as I have posted with just a minor change in the type. Below code works for both email as well as whatsapp sharing:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
File F = new File(filePath);
F.setReadable(true, false);
Uri fileURI = Uri.fromFile(F);
Log.e("Share", "Share file url is " + fileURI);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Shared file");
sharingIntent.setType("audio/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, fileURI);

Share Intent.ACTION_SEND

I would love to share a picture with a text or url.
I'm using this code but I am only sharing the image, and changing the order of the "type" makes me share both but only as email / gmail
What am I doing wrong? my code is:
edit1
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
share.setType("*/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Wallpaper/1.jpg"));
share.putExtra(Intent.EXTRA_TEXT, "helloworld");
startActivity(Intent.createChooser(share, (getApplicationContext().getString(R.string.condividi))));
try this
File DoutFile = new File(path);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(DoutFile));
share.putExtra(Intent.EXTRA_TEXT,
"" + getResources().getString(R.string.app_name));
startActivity(Intent.createChooser(share, "Share Image"));
Specify MIME type also for the text. "text/plain" is the type of text data MIME. Try using "*/*" as MIME, so you can send any generic data type.
Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.
More info about ACTION_SEND_MULTPLE and handling MIME types:
http://developer.android.com/reference/android/content/Intent.html
If you want to send multiple files then use the following code :-
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Add any subject");
intent.setType("image/*"); /* sharing any type of image. Modify to your need */
ArrayList<Uri> files = new ArrayList<Uri>();
for(String path : filesToSend /* List of images you want to send */) {
File file = new File(path);
Uri uri = Uri.fromFile(file);
files.add(uri);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); /* adding files to intent */
startActivity(intent);

How to attach an image from SD Card to an email?

I am trying to attach an image from SD Card to an email (from my app to Gmail app).
Every time I try, I select Gmail app and it closes, it doesn't attach the file.
Let's say the image path is: /sdcard/DCIM/Snapseed/Snapseed4.jpg. This is the code I am using to send the email:
Intent emailintent2 = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailintent2.setType("image/*");
emailintent2.putExtra(Intent.EXTRA_EMAIL, emailaddress2);
emailintent2.putExtra(Intent.EXTRA_SUBJECT, CorAsunto);
emailintent2.putExtra(Intent.EXTRA_TEXT, message2);
Uri uris = Uri.fromFile(new File(Environment.getExternalStorageDirectory()
+ "/DCIM/Snapseed/Snapseed4.jpg"));
emailintent2.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailintent2);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("SDCARD IMAGE PATH"));
startActivity(Intent.createChooser(emailIntent,"Share image using"));

The mp3 files of my app are not sent through gmail

I have a problem, I'm triying to send a mp3 file to gmail.
My code works good so far for whatsapp, hotmail, bluetooth... but it doesn't work with gmail
This is my code:
File sdCard = Environment.getExternalStorageDirectory();
String path = sdCard.getAbsolutePath() + "/" +"miApp"+"/tono.mp3";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("audio/mp3");
intent.putExtra(Intent.EXTRA_SUBJECT, "Asunto");
intent.putExtra(Intent.EXTRA_TEXT, "Prueba");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///" + path));
startActivity(intent);
I try with various types of mime but with the same results
"audio/x-mpeg-3"
"video/mpeg"
"video/x-mpeg"
"audio/mpeg"
What's wrong?
This worked for me
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("audio/mp3");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/miApp/tono.mp3"));
startActivity(i);

Categories

Resources