I am trying to send an attachment with my email programmatically. The attachment is my db file. I was able to get it done when the DB file is on the SD card.However when it is internal then it keeps complaining that the file is not found
Here is my code:
String path = "/data/data/MyPackageName/databases/mydb.db"
Intent email = new Intent(android.content.Intent.ACTION_SEND);
email.setType("plain/text");
email.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
email.putExtra(android.content.Intent.EXTRA_TEXT, "Hiii");
email.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));
Any idea why it does not work in this path? Am I missing something or does attachment works for files on external storage only?
That’s correct behavior. The file is in your application’s private storage, and can not be accessed by any other process. You either need to copy it to external storage first, or implement a content-provider to pass on a file descriptor for it.
Refer to this project for an excellent example of how to implement a ContentProvider for files.