I want to attach a .txt
file in email for sending in Android. The file is located at /data/data/com.PackageName/files/
. I am trying as;
private void Share(String file_name) {
try {
String filelocation = "/data/data/com.PackageName/files/awais.txt";
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
String message="File to be shared is " + file_name + ".";
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://"+filelocation));
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setData(Uri.parse("mailto:xyz@gmail.com"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch(Exception e) {
System.out.println("is exception raises during sending mail"+e);
}
}
I have added the permissions in the AndroidMenifest
as
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
But Android gives the error.
Permission denied for the attachment.
For the more clarification see the picture below.
Any help?