I have 2 custom file extensions *.abc
and *.xyz
.
I have written Intent filters for activities where file having *.abc
extension should be opened in Activity1
and *.xyz
should be open in Activity2
Those files having serialized java objects and not plain text files.
These are intent filters for those activities in AndroidManifest.xml
<activity
android:name=".ui.Activity1">
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.abc" />
</intent-filter>
</activity>
<activity
android:name=".ui.Activity2">
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.xyz" />
</intent-filter>
</activity>
I am able to register those extension in android system and my app activities are showing in app chooser of Android System UI
I am printing URI info in logcat as follows
Timber.i(uri.toString())
val mimeType = contentResolver.getType(uri)
Timber.i(mimeType)
Logcat when file opened from WhatsApp
content://com.whatsapp.provider.media/item/5237
application/octet-stream
Logcat when file opened from Solid Explorer
content://pl.solidexplorer2.files/storage/emulated/0/Download/File1.abc
application/*
But when tap either of file (custom extension) it shows both Activities as openable Intent, for eg. If click on file file1.abc it shows both Intent Filters of extensions as Activity1 and Activity2
I want to make those extensions Activity Specific like if click on file with extension *.abc it should only have Activity1 in Intent Chooser of Android System UI
I have tried few methods explained in other answers but those doesn't seems to work properly for both file format with content type URI
Some solutions only working when file opened from File Browsers like Solid Explorer but doesn't work when open from apps like WhatsApp which uses MIME type as media
Intent filter below properly worked with Solid Explorer. It is filtering activity based on custom file extension. But same Intent Filter won't work for Android System's Chooser dialog as it doesn't work in apps like WhatsApp or Gmail which uses Android System's Intent Chooser
<activity
android:name=".ui.Activity1">
<intent-filter>
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.abc"
android:scheme="content" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".ui.Activity2">
<intent-filter>
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.xyz"
android:scheme="content" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Any help will be appreciated. Thanks.