I tried many ways but I can't do this.
I have a *.txt file. I want to share it via Bluetooth, wifi, email and ....
When i used this code i cant share the file:
File file = new File(Environment.getExternalStorageDirectory(), "Email-Ghap/Emails.txt");
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/txt");
sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
startActivity(Intent.createChooser(sharingIntent, "share file with"));
Totally I want this: when the user clicked on the share button and chooses one email sender like Gmail for sharing. the file must be attached file for the new email ...
I found this link https://stackoverflow.com/a/16036249/4016922
But it shares txt file content. I want to share the file not the content of the txt file
Change your Code Like this.
From
File file = new File(Environment.getExternalStorageDirectory(), "Email-Ghap/Emails.txt");
To
File file = new File(Environment.getExternalStorageDirectory() + "/" + "Email-Ghap/Emails.txt");
from:
sharingIntent.setType("*/txt");
To
sharingIntent.setType("text/*");
so yourFinal Code Looks Like
File file = new File(Environment.getExternalStorageDirectory().toString() + "/" + "abc.txt");
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
startActivity(Intent.createChooser(sharingIntent, "share file with"));
Related
I want to share my csv file to any action like Bluetooth, send to email ,etc
final String filename = Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, filename);
sharingIntent.setType("text/comma_separated_values/csv");
startActivity(Intent.createChooser(sharingIntent, "share file with"));
the output will be no request containt no data
I think that the filename requires a file:// prefix. Android, for sharing any types of file requires a universal identifier or a Uri.
final String fileUriString = "file://" + Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";
Also, change the type to text/csv.
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse( fileUriString ) ) ;
sharingIntent.setType("text/csv");
startActivity(Intent.createChooser(sharingIntent, "share file with"));
See this answer for more.
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
My app use MP3 files with MediaPlayer, i want to make a button than will share an MP3 file to whatsapp.
my code is this:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
String audioClipFileName="bell.mp3";
sendIntent.setType("audio/mp3");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+"/sdcard/"+audioClipFileName));
startActivity(sendIntent);
but its not working.why is not working?how can i solve this issue?
You need use Environment and not hardcode path, for example, if your file is in sdcard root use a code like this:
File root = Environment.getExternalStorageDirectory().getPath();
String fname = "bell.mp3";
file = new File(root, fname);
Intent shareCaptionIntent = new Intent(Intent.ACTION_SEND);
shareCaptionIntent.setType("audio/mp3");
shareCaptionIntent.putExtra(Intent.EXTRA_TEXT, "YOURTEXT");
shareCaptionIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.toString()));
startActivity(Intent.createChooser(shareCaptionIntent, "Share in:"));
If a resource use this:
Uri.parse("android.resource://com.my.package/raw/" + fname);
Or resource ID
Uri.parse("android.resource://com.my.package/" + R.raw.bell.mp3);
Any error please share logcat
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).
Hi i am developing an android application with email functionality. Here i need to send a CSV file from my path data/data/mypackage/files folder. I am storing the csv file there.It is saving there good.My csv file size is just 245 bytes only. But when i tried to send that file throught mail functionality of android is displaying "File too Large to attach.." message is displaying.
Here is my code:
String filelocation="file:///data/data/my package/files/excerDB.zip";
final Intent emailIntent = new
Intent(android.content.Intent.ACTION_SEND);
emailIntent .setType("plain/text");
emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"purpletalk.raghu#gmail.com"});
emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, "Attendence Report");
emailIntent .putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(filelocation));
startActivity( emailIntent);
But it is not working for me. Please advice me how can i send my file as a attachment to mail in my application.
i hope this code will help u
String FILE = Environment.getExternalStorageDirectory() + File.separator
+ "Foldername";
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
// sendIntent.setType("text/html");
sendIntent.setType("application/csv");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
sendIntent.putExtra(Intent.EXTRA_TEXT, "");
String temp_path = FILE + "/" + "Filename.csv";
File F = new File(temp_path);
Uri U = Uri.fromFile(F);
sendIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(sendIntent, "Send Mail"));
Enjoy this code!