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
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 using android: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 the android:mimeType
so experiment with android: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.