Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gmail app-Mail Attachment URI issue

Tags:

android

gmail

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

I get link in pattern like content://gmail-ls/messages/mailid%40gmail.com/4/attachments/0.1/BEST/false

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.

like image 339
Jana Avatar asked Jun 30 '11 10:06

Jana


People also ask

Why is my Gmail not sending emails with attachments on Android?

Some temporary files stored in the Cache may be keeping your email from getting sent. Simply go to Settings>Privacy and Security and clear the cache and cookies. This is one of the best ways to fix the 'Can't Send Emails With Attachments From Gmail Account' issue.

Why attachment is not downloading in Gmail in mobile?

If you can't download attachments from Gmail, it may indicate that your network is running slow or unstable. To confirm this, run a test using Fast.com to measure your network's upload and download bandwidth.

Why attachments are not opening in Gmail?

Attachments won't open or download If attachments won't upload or download, try these steps in order: On your computer, check that you're using a supported browser. Try turning off extensions you have on your browser one at a time. Clear your browser's cache and cookies.


1 Answers

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 (attachment.read(buffer) > 0)
                tmp.write(buffer);
            tmp.close();
            attachment.close();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    }
    return getCacheDir().getPath() + "/temp.myfile";

Reember to add this to your manifest.

    <intent-filter>
            <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" />

            <data
                android:host="*"
                android:mimeType="application/octet-stream"
                android:pathPattern=".*\\.tsconfig" />
            <!-- To handle gmail attachments -->
    </intent-filter>
like image 156
LokiDroid Avatar answered Oct 21 '22 02:10

LokiDroid