Android Gmail app-Mail Attachment URI issue


I have to open attachment file from gmail app thru my app.

I get link in pattern like content://gmail-ls/messages/

My problem is the link is not unique for each file in the mail client..
One or more file has same Uri.

Is there any way to get the file name or email sent date so that I can come over this issue.

Thanks in advance.

Best Solution

As shown below you can make a local copy of the same attachment and work on that file. Directly you wont be able to access that file which is on the gmail server.

    Uri uri = getIntent().getData();
    if (uri != null) {
    try {
        InputStream attachment = getContentResolver().openInputStream(uri);
        if (attachment == null)
            Log.e("GMAIL ATTACHMENT", "Mail attachment failed to resolve");
        else {

            FileOutputStream tmp = new FileOutputStream(getCacheDir().getPath() + "/temp.myfile");
            byte[] buffer = new byte[1024];
            while ( > 0)
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    return getCacheDir().getPath() + "/temp.myfile";

Reember to add this to your manifest.

            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.EDIT" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

                android:pathPattern=".*\\.tsconfig" />
            <!-- To handle gmail attachments -->
Related Question