How to send .text file by using intent in android? - android

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"));

Related

android studio share CSV file request contain no data

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.

sharing gif with telegram android

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 to attach .amr file to mail in Android

I want to attach amr file in attachment but i am unable to attach.
My code is as follows:
Intent emailIntent = new Intent(
Intent.ACTION_SEND);
Uri U = Uri.parse(path of amr file);
//System.out.println("uri is:" + U);
emailIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "" });
emailIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT,
" from ..");
emailIntent.putExtra(
android.content.Intent.EXTRA_TEXT, ""
+ "\n" + "\n" + "Through application name");
emailIntent.setType("audio/rfc822");
//emailIntent.setType("audio/*");
// emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
emailIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(emailIntent,
""));
i have used emailIntent.setType("audio/rfc822") , emailIntent.setType("audio/*"); and emailIntent.setType("audio/amr"); but no luck
Any help will be appreciated.
have you tried using,
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
Activity Action: Deliver multiple data to someone else.

Android: how to send email intent, using file with special characters?

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 );

How to send csv file as attachment in android?

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!

Categories

Resources