简体   繁体   中英

ContentResolver — how to get file path of attachment

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM