Background
It is a very known feature on modern desktop OSs to be able to handle files, allowing the user to open them from the file-manager and other apps, as "file assosiation" configuration.
The problem
So far, it wasn't such a convenient thing on Android, for both users and developers, to set an association of a file type.
Up to Android API 30 (Android 11, AKA Android R), you had to use some weird workarounds, especially if the file isn't a known one.
Example for "xyz" :
<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:scheme="content" />
<data android:scheme="file" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.xyz" />
<data android:pathPattern=".*\\..*\\.xyz" />
<data android:pathPattern=".*\\..*\\..*\\.xyz" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.xyz" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.xyz" />
...
</intent-filter>
And if it's a known one, such as a ZIP file, maybe something like this (not sure if it's the minimal/best one) :
<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:scheme="package" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="application/x-zip" />
<data android:mimeType="application/x-zip-compressed" />
<data android:mimeType="application/zip" />
</intent-filter>
In fact, even if it's a known one, you should still consider using both ways, as some apps handle only the first way.
But on Android API 31 (Android 12, AKA Android S) , it seems it has changed and we might be able to write less in the manifest (sadly probably only if minimal API is 31).
What I've found
The only thing I've found for this is on the docs:
- https://developer.android.com/reference/android/R.attr#pathSuffix
- https://developer.android.com/reference/android/R.attr#pathAdvancedPattern
Sadly, there were no examples that I could find, and I don't even know if it's the official way to handle files now.
The questions
- Is it now really the true, valid, official way to handle files on Android ?
- How should I use it now? Do I still need to set mimeType ? Will this work for files of any kind, whether known or not?
- Is it possible to set it up this way, and stop using the ways I've mentioned? Or this is only if I set the minSdk to be 31 ?
- Does it affect the experience for users, in any way ?