I have a custom file type/extension that I want to associate my app with.
As far as I know, the data element is made for this purpose, but I can't get it working. http://developer.android.com/guide/topics/manifest/data-element.html According to the docs, and a lot of forum posts, it should work like this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/pdf" />
</intent-filter>
Well, it does not work. What did I do wrong? I simply want to declare my own file type.
Those who having issue with other File Manager\Explorer apps, as @yuku and @phyrum-tea answered
This works with LG default file manager app
but could not work with ES File Explorer and other File Managers so i added
then it works with ES Explorer but LG file manager could not detect file type so my solution is
You need multiple intent filters to address different situation you want to handle.
Example 1, handle http requests without mimetypes:
Handle with mimetypes, where the suffix is irrelevant:
Handle intent from a file browser app:
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.
Try adding
The answeres given by Phyrum Tea and yuku are very informative already.
I want to add that starting with Android 7.0 Nougat there is a change to the way file sharing between apps is handled:
From official Android 7.0 Changes:
If you have your own custom file ending without a specific
mime-type
(or i guess even with one) you may have to add a secondscheme
value to yourintent-filter
to make it work withFileProviders
too.Example:
The important thing here is the addition of
to the filter.
I had a hard time finding out about this little change which kept my activity from opening on Android 7.0 devices while everything was fine on older versions. I hope it helps someone.
You try this it will help for you.Instead of pdf you can use other extensions also. First you have to add read external storage permission in androidmanifest.xml file.
Then in the androidmanifest file in the Activity tag, you add an intent-filter as shown below.
Finally in your code, you get path of the pdf file as shown below: