I want to be able to download a file with a particular extension from the 'net, and have it passed to my application to deal with it, but I haven't been able to figure out the intent filter. The filetype is not included in the mimetypes, and I tried using
<data android:path="*.ext" />
but I couldn't get that to work.
None of the above work properly, for VIEW or SEND actions, if the suffix is not registered with a MIME type in Android's system=wide MIME database. The only settings I've found that fire for the specified suffix include
android:mimeType="*/*"
, but then the action fires for ALL files. Clearly NOT what you want!I can't find any proper solution without adding the mime and suffix to the Android mime database, so far, I haven't found a way to do that. If anyone knows, a pointer would be terrific.
Using the filter as below to open from browser, gmail & file browser (Tested). NOTE: Please do not merge two filters, that will make browser ignored your app(Tested).
I've been trying to get this to work for ages and have tried basicly all the suggested solutions and still cannot get Android to recognise specific file extensions. I have an intent-filter with a
"*/*"
mimetype which is the only thing that seems to work and file-browsers now list my app as an option for opening files, however my app is now shown as an option for opening ANY KIND of file even though I've specified specific file extensions using the pathPattern tag. This goes so far that even when I try to view/edit a contact in my contacts list Android asks me if I want to use my app to view the contact, and that is just one of many situations where this occurs, VERY VERY annoying.Eventually I found this google groups post with a similar question to which an actual Android framework engineer replied. She explains that android simply does not know anything about file-extensions, only MIME-types (https://groups.google.com/forum/#!topic/android-developers/a7qsSl3vQq0).
So from what I've seen, tried and read, Android simply cannot distinguish between file-extensions and the pathPattern tag is basicly a gigantic waste of time and energy. If you are fortunate enough to only need files of a certain mime-type (say text, video or audio), you can use an intent-filter with a mime-type. If you need a specific file-extension or a mime-type not known by Android however then you're out of luck.
If I'm wrong about any of this please tell me, so far I've read every post and tried every proposed solution I could find but none have worked.
I could write another page or two about how common these kinds of things seem to be in Android and how screwed up the developer experience is, but I'll save you my angry rantings ;). Hope I saved someone some trouble.
Rather than
android:path
, tryandroid:mimeType
, with a value of the MIME type of this particular piece of content. Also,android:path
does not accept wildcards -- useandroid:pathPattern
for that.I must admit that the simple task of opening attachments from emails and files from the filesystem on Android has been one of the more maddening experiences ever. It is easy to handle too many files or too few. But getting it just right is hard. Most of the solutions posted on stackoverflow didn't work correctly for me.
My requirements were:
Probably the best way to go about this task is to specify a custom MIME Type for your attachments. And you will probably also choose to have a custom file extension. So let's say that our app is called "Cool App" and we generate file attachments that have ".cool" at the end.
This is the closest I got got to my goal and it works... satisfactory.
Notes:
pathPattern
seems to be more or less ignored for attachments (when usingandroid:scheme="content"
). If somebody gets the pathPattern to respond only to certain patterns I would be thrilled to see how.android:host="*"
attribute.intent-filter
blocks are merged but I haven't verified this.android:scheme="http"
can be used. Note that certain browsers might mess up theandroid:mimeType
so experiment withandroid:mimeType="*/*"
and check in the debugger what is actually passed through and then tighten the filtering to not end up being that annoying app that handles everything.intent-filter
was tested with the Samsung's "My Files" app on a Galaxy S3. The FX Explorer still refuses to properly open the file and I also noticed that the app icon is not used for the files. Again, if anyone gets that to work please comment below.I hope you will find this useful and that you won't have to waste days going through all possible combinations. There is room for improvement so comments are welcome.
Brian's answer above got me 90% of the way there. To finish it off, for mime type I used
I suspect that previous posters have attempted to post the same detail, but the withough qoting the star slash star as code, stackoverflow diplays it as just a slash.