I am able to attach a text file to an email with this code:
String fileName = "test.txt";
path = "file://" + Environment.getExternalStorageDirectory() + "/" + fileName;
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
startActivity(Intent.createChooser(sendIntent, "Email"));
However, emails sent through gmail do not contain the attachment if fileName="test#.txt".
I tried Encoding the path with URLEncoder, as below, but this doesn't work with either "text.txt" or "text#.txt".
I'm probably missing something simple here, but how should I encode file paths with special characters for send intents?
String fileName = "test.txt";
// String fileName = "test#.txt";
String path = "file://" + Environment.getExternalStorageDirectory() + "/" + fileName;
String encPath = URLEncoder.encode(path);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(encPath));
startActivity(Intent.createChooser(sendIntent, "Email"));
That's because you didn't encode the URL correctly. Instead of only encoding the filename, you encoded the full URL, which results in:
file://te#st.txt
file%3A%2F%2Fte%23st.txt
Try this instead:
String path = "file://" + Environment.getExternalStorageDirectory() + "/";
path += URLEncoder.encode( fileName );
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 want to share an animated gif file with telegram. I'm using following code:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/gif");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment
.getExternalStorageDirectory()
+ FOLDER_NAME
+ fileName + ".gif"));
share.setPackage("org.telegram.messenger");
startActivity(share);
this code open telegram but when I select a chat; there is not any thing to share.
Excuse me for bad English.
I solved it by changing code to
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/gif");
String imagePath = Environment
.getExternalStorageDirectory()
+ FOLDER_NAME
+ fileName + ".gif";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("org.telegram.messenger");
startActivity(share);
How i can send the txt file that i created with the FileOutputStream trought of screemShare
i can also not found the file path
//x = "/data/data/" + getPackageName() +"/pec.txt";
this is my code:
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
Uri uri = Uri.parse(x);
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
intent.putExtra(android.content.Intent.EXTRA_TEXT, "PEC");
startActivity(Intent.createChooser(intent,"Imprimir"));
Check this example that work for me HERE
I am sending a mail by using below code and i need to send a .text file also using gmail only.
How can i do it? Please can any one help me?
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("") +
"?subject=" + Uri.encode("Sample Text") +
"&body=" + Uri.encode("Hi");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
Thanking in Advance.
File sd = Environment.getExternalStorageDirectory();
File fileDir= new File(sd, "dir_path");
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileDir.getAbsolutePath() + "/"
+ FILE_TXT
startActivity(Intent.createChooser(email , "Email: Text File"));
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!