Question

I need help in accessing the attachment received in an email.

I have setup intent filter for my activity and on clicking the attachment in the gmail app, my activity is launched with intent containing following Uri.

content://gmail-ls/xxxx@gmail.com/messages/2407/attachments/0.1/BEST/false

I have tried following query and filename returned is null.

String[] projection = {MediaStore.MediaColumns.DATA};
Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
if (c.moveToFirst()) {
    fileName = c.getString(0);
}

Anyone, please let me know how can I access the file received in the attachment ?

Thanks.

Was it helpful?

Solution

Anyone, please let me know how can I access the file received in the attachment ?

There isn't necessarily a file at all, let alone one that you have direct access to. Gmail, in particular, had better be storing its attachments in a place where other apps cannot access them directly.

To use the attachment, use the Uri with a ContentResolver to get an InputStream on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top