I can open custom file extensions when accessing browser links without problem. How can I associate my app with file extensions locally on my device?
Specifically I would like to:
1) Open a file that has been downloaded - I drag the Notifications screen from the top of my display which lists recent .xm files that have been downloaded. I would like to be able to tap on those and have my application open these files.
2) Likewise with other file explorer apps if possible.
Here are my intent filters. What am I missing?
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:pathPattern=".*\\.xm" />
<data android:host="*" />
<data android:mimeType="text/plain"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.xm" />
<data android:host="*" />
</intent-filter>
UPDATE: See below filters
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/octet-stream"
android:host="*"
android:pathPattern=".*\\.xm"
/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/mytype"
android:host="*"
android:pathPattern=".*\\.xm"
/>
This post has helped me solved the problem. I'm including the required intent filters above in the original question.
Related
I am trying to let my app share and handle custom file extension and upon clicking it, it will open my app then I parse it.
I have looked into different ways like LIKE THIS for example and THIS, but clicking on the file from FileBrowser or WhatsApp for example is not detecting my app.
I am using the navigation component if it helps
I am not sure what I am doing wrong, I would appreciate it if someone have a working example.
Thanks.
This is some of the code I tried (I am testing with txt as it is an easy extension) (1)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern="*.txt" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/txt" />
</intent-filter>
I also tried (2)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.txt" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.txt"
android:scheme="file" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />
<!--
Work around Android's ugly primitive PatternMatcher
implementation that can't cope with finding a . early in
the path unless it's explicitly matched.
-->
<data android:host="*" />
<data android:pathPattern=".*\\.txt" />
<data android:pathPattern=".*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.txt" />
<!-- keep going if you need more -->
</intent-filter>
and (3)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="text/plain" />
</intent-filter>
I finally my issue, I was testing multiple things at the same time.
I ended up using
<!-- this is needed for apps like whatsapp, it doesn't provide extension, so you can't add path -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data
android:mimeType="application/octet-stream"
android:scheme="content" />
</intent-filter>
<!-- this is needed for apps like explorer -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.ext"
android:scheme="content" />
</intent-filter>
If you use mimeType="*/* then check logcat (no filter at all), search for content:// then you see what is the Android sending to your app, then modify the IntentFilter to match what you want. Some apps don't send the extension so using pathPattern was not working with it, Also using schema = content is needed
Thanks #CommonsWare for the help.
I'm trying to let user have the option to open pdf files through my app.
So, when a user clicks on a pdf file from the file manager they should have the option to open it with my app along with other pdf reader apps if available in their device.
I've added the following intent filters in the manifest by scouring through various answer here. They seem to work below Api 29 (my app shows in the list upon clicking a pdf file). But for API Q the app isn't showing on the list.
Intents filters:
<!--For pdf-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content"
android:host="*"
android:pathPattern=".*\\.pdf"
android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.pdf"
android:scheme="file" />
</intent-filter>
<intent-filter android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data android:host="*" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\.pdf" />
<data android:pathPattern=".*\\.pdf" />
<data android:scheme="content" />
</intent-filter>
<!--end pdf-->
How can I allow pdf files to be opened with my app in Android Q and above too?
PS: All necessary permissions are taken
I'm using this code for this
<activity
android:name=".OpenPdfActivity"
android:theme="#style/OpenPdfActTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/pdf"
android:scheme="file" />
<data
android:mimeType="application/pdf"
android:scheme="content" />
</intent-filter>
</activity>
I want all files of my type (.xxx) to be open with my application on an Oculus Go.
For that I have tried a lot of things in my AndroidManifest.xml file. For now, I have all these intent filters in the main activity :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.xxx" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.xxx" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/x-compressed" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/x-zip-compressed" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/zip" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="multipart/x-zip" />
</intent-filter>
The 4 intent filters with a mime type are for zip files. It's because my file type is ".zip" file renamed to ".xxx".
I have downloaded a .xxx file with the oculus browser and then click on it on the right panel. Nothing happened ...
I also tried with a zip file. Nothing happened ...
Is it possible to do a file association on Oculus Go ?
Am I doing something wrong ?
Thanks in advance.
TL;DR No, this is not supported yet.
Oculus Browser doesn't launch intents for downloaded items. It does open video files; it handles video files as a special case.
my app's file-intent handles attachments with a custom file extension in emails sent from aol.com, but not from Thunderbird. Has anyone had this issue? I see some comments on mime-type handling. My file type is basically text with a ".hmrx" extension.
Is this a matter of adding something more to the intent-filter?
I don't want my app to be suggested for handling general text files... I don't see the problem:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.hmrx" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/octet-stream" />
<data android:scheme="content" />
<data android:pathPattern=".*\\.hmrx" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/octet-stream" />
<data android:scheme="file" />
<data android:pathPattern=".*\\.hmrx" />
</intent-filter>
EDIT:
By the way, I tried adding
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:mimeType="text/plain" />
<data android:pathPattern=".*\\.hmrx" />
</intent-filter>
But then it offers to open regular text files with my app.. which I dont want.
Apparently this is happening because Thunderbird send just about any kind of text as inline instead of as a "real" attachment. Anybody successfully managed this?
Thanks
I have a custom file type with the extension .myext.
I've read android doc and many SO posts to understand how to configure intent filter to associate these files to my app. It works but not properly.
When I use this intent filter :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/*" />
<data android:pathPattern=".*\\.myext" />
<data android:host="*" />
</intent-filter>
then it links .myext files to my app, but also every file that has no app assoiated. So I can open .otherext file which I don't want.
Then I found this answer https://stackoverflow.com/a/5097734/575481 which suggest to have multiple intent-filter, So I get :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.myext" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.myext" />
</intent-filter>
but this doesn't seem to work for me.
What I want is that : my apps opens only .myext files. Do you have any idea ?
Furthermore I will need to open some other file ext (.myext1, .myext2) , but I guess once I get the proper intent-filter, I just have to duplicate it for the others with the extension, right ?
I got it. In my case I am trying to get a .ppp from e-mail and it was fetching any file.
this is the working filter
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="content" android:pathPattern=".*\\.ppp" android:mimeType="application/ppp"/>
</intent-filter>
on your activity's onCreate put a breakpoint and check the values in
getIntent()
specifically mData should give you what to write for the android:scheme and mType what to write for the android.mimeType