I have a simple app which I am using to spike sending attachments.
I have managed to send a text file from the SD card (although I couldn't get this to work with a file created in the apps private area using openFileOutput(fileName, 0)
) but I now want to send a database.
By debugging I can verify the database exists and has an entry in its only table. My code to send looks like this:
gmailButton = (Button) findViewById(R.id.button);
gmailButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subject line");
sendIntent.putExtra(Intent.EXTRA_TEXT,"Body of email");
Uri uri = Uri.fromFile(getDatabasePath("TEST_DB"));
//uri = file:///data/data/com.gmailspike/databases/TEST_DB
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("application/octet-stream");
startActivity(Intent.createChooser(sendIntent,"Email:"));
}
})
;
However, when the email client opens the attachment has a size of 0 bytes and if I touch to open the attachment the client says the file cannot be found.
Any ideas? I'm not sure the mime type is correct, or even if it is important!