I am trying to attach the file from the /data folder of the device.
I have successfully created "abc.txt" in /data folder, I can see the file at that place.
I am using below code to send email:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{[email protected]});
intent.putExtra(Intent.EXTRA_STREAM,
Uri.parse(Environment.getDataDirectory()+"/abc.txt"));
intent.putExtra(Intent.EXTRA_TEXT, "hello..");
startActivity(Intent.createChooser(intent, email_chooser_title));
but I am unable to receive the attachments..
pl. let me know what's the mistake I have done..
thanks.
Right click on the folder itself. In the menu that pops up, choose “Send to”, then choose “Compressed (zipped) folder” Rename the zipped folder if necessary, then hit enter. Right click the zipped folder, then choose “Send to” again, but this time choose “Mail Recipient”
Send as the body of an email message Open the file you want to send. In the Quick Access Toolbar, click Send to Mail Recipient to open an email message. Your file will appear in the body of the message. Enter the recipients' aliases, edit the subject line and message body as necessary, and then click Send.
In a new email message, select the Format Text tab in the ribbon. Select Plain Text or Rich Text. Select the Message tab in the ribbon and then select Attach File.
You must copy the file to the external directory (aka SD Card). It's because the email application cannot access your data directory (in the same way that you can't access other app's data directory)
Try using this code:
File sdCard = Environment.getExternalStorageDirectory();
PATH=sdCard.toString()+"/abc.txt";
Intent intent=new Intent(Intent.ACTION_SEND);
intent.setType("**/**");// or intent.setType("text/plain");
String[] recipients={"[email protected]");
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT,getResources().getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+PATH));
intent.putExtra(Intent.EXTRA_TEXT, "hello..");
startActivity(Intent.createChooser(intent,""));
Make sure there is abc.txt file in your Device/Emulator's sdcard.
Also include these two permissions in your project's manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With