10

I have been struggling with this for days now.

I am trying to register my activity via intent filter to open a specific custom file type with gmail.

The problem is no matter what I try, either I do not get the option to open the file or any attachment of any file type (including mine) is given the option to open with my application.

I believe the problem is that the URI supplied by gmail doesn't have any file details contained inside it.

There are plenty of people who have asked this same question however the solution to all of them never limit the intent filter to just the custom file type.

The current intent filter in my Android Manifest is the following...

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data
                    host="*"
                    android:mimeType="*/*"
                    android:pathPattern=".*\\.abc"
                    android:scheme="content" />
            </intent-filter>

Just to reiterate, this intent filter adds the option to open any attachment from gmail with my application.

Any help would be much appreciated

1
  • we want attachment file sent to mail... Jan 10, 2013 at 11:34

1 Answer 1

6

There is not necessarily a file extension on content:// Uri values pointing to files. AFAIK, Gmail does not include a file extension on theirs, and so it will not match your pathPattern. Also, host is missing the android: namespace prefix.

If the email will be sent with a distinct MIME type for your file, use that in android:mimeType and drop the remaining <data> attributes. If the email will not be sent with a distinct MIME type for your file, then AFAIK you are out of luck.

4
  • Hi CommonsWare. Thanks for your reply. I find it a bit weird that you cannot declare what files you want to open in gmail? Is it just gmail that I'm going to have this issue with? Jan 16, 2013 at 10:06
  • @DiscoS2: The issue is that you are trying to make the association based upon file extension. Android emphasizes MIME type and does very little with file extension. In principle, you could encounter this problem with any sort of app that serves up files via a ContentProvider. Jan 16, 2013 at 12:19
  • Ok thats fair enough, just a bit of a problem if I then want to send a file from a desktop client and not my application as I don't have any control over the MIME type. Thanks for your help CommonsWare and your book is also very helpful :0 Jan 16, 2013 at 12:33
  • 2
    Unfortunately the MIME type is set by the sender, you can't rely on it being set correctly. This is nearly always the case for custom MIME types (as the sending end is unlikely to have your application, or indeed to even be an Android device). Which means that relying on the MIME type for gmail attachments isn't particularly useful. About the only thing you can do here is associate with application/octet-stream, but that's not really a good user experience either. As it stands, this is not really a soluble problem. Jul 23, 2013 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.