Sending attachment does not work for internal storage files

I am trying to send an attachment with my letter programmatically. The attachment is my db file. I was able to do this when the DB file is on the SD card. However, when it is internal, it keeps on complaining that the file was 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 this doesn't work along the way? Am I missing something or does the application only work for files on external storage?

+3


source to share


1 answer


This is the correct behavior. The file is in your private application storage and cannot be accessed by any other process. You either need to copy it to external storage first, or implement a content provider to pass a file descriptor for it.



Check out this project for a great example of how to implement a ContentProvider for files.

+4


source







All Articles