I'm trying to open any file with a .conf
extension in my android app. Here's what I have in my AndroidManifest.xml
:
<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:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.conf" />
</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="content" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.conf" />
</intent-filter>
But, when I tap on a .conf
file in the Downlaods folder, it says "Can't open file."
Here's what I get when I use Intent Intercept:
What am I doing wrong?
Remove:
from both
<intent-filter>
entries and:from the
content
one.File extensions are not used much on Android. Starting with Android Q, files are not used much on Android. There is no requirement for a
ContentProvider
to put a file-like extension on acontent
Uri
, as you can see from theUri
in your screenshot.If you wish to support common
Intent
actions likeACTION_VIEW
, your best bet is to save the file in a common meta-format (e.g., JSON, XML) with a file extension that matches, then have your<intent-filter>
filter on the corresponding MIME type. You will need to deal with the possibility that the user chooses a file that was not created by your app, though technically you need to deal with that even with your custom extension.