Androidite Android Email Database

I hope that I can submit the SQLite database that I use in my application as a backup form that the user can perform. My current code is below, the database is displayed as an attachment in the email intent and the email is sent, but the application is not sent.

File file = new File(Environment.getDataDirectory(), "/data/com.app/databases/databaseName"); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{""}); intent.putExtra(Intent.EXTRA_SUBJECT, "Backup"); intent.putExtra(Intent.EXTRA_TEXT, ""); intent.setType("application/octet-stream"); intent.putExtra(Intent.EXTRA_STREAM, file.toURI()); startActivity(Intent.createChooser(intent, "Send Email")); 
+7
source share
4 answers

I remember I had this exact problem a while ago. I'm not sure what I did to fix this, but my working code looks something like this ...

 File root = Environment.getExternalStorageDirectory(); String fileName = "foo.txt"; if (root.canWrite()) { attachment = new File(root, fileName); } email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment)); startActivity(Intent.createChooser(email, "Send Email")); 

I remember that since I used the SD card for storage, it did not send my application if I was still connected to the computer via USB (since it saved the SD card and is busy). As soon as I disconnected the USB connection, everything worked out well.

+3
source

Export your database to an SD card before attempting to email it. You cannot add attachments to the application data / data folder. These files are private to your application.

+4
source

see this link: http://www.openintents.org/en/node/121 you need to go through the URI

decision:

files must be attached as

 sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mysong.mp3")); 

You need an additional / in file: /// (not in the Stack Overflow column), because otherwise GMail discards the attachment just before sending a message that the file path is incorrect.

SO WHAT YOU NEED IN EXTRA / in the file and it is not lost .... I hope this helps

0
source

stack overflow

The above SO answer does a great job of how you copy a DB file, send it by email as an attachment, and then delete the copied file. Check this.

0
source

All Articles