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.
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).
The only thing I've found for this is on the docs:
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.
OK after some research by myself, here are my answers to my questions:
Seems so.
Seems it's possible to just use this for the first part:
<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:pathSuffix=".xyz" />
...
</intent-filter>
The second part stays the same because it is used in special cases.
However, I failed to use the alternative of pathAdvancedPattern
for some reason (tried using <data android:pathAdvancedPattern=".*\\.xyz" />
).
Sadly no. I've requested it to be a syntactic sugar from pathSuffix to pathPattern for pre-Android-12, here.
Doesn't seem so.