Let me first say I've been reading some similar questions here, for example this one, but was only able to solve my issue partially and still having doubts.
I'm not sure how custom file registration works in Android, I don't know if a new file type can be registered on app install or it can only be done with an intent-filter in the activity that will open the file, and second, I'm not quite sure if there is any possibility to automatically associate your own custom file with your app, or this is something that only the user can do.
That said, I'm creating a custom file type (.aw extension) to be opened with my app and with the next intent-filter I can open the file from the file explorer -for example- in my Android 9 Huawei, but it's not working at all with other devices, like my old Android 5 tablet (which says "Cannot open file" on file click) or my friend Android 9 Samsung. I said that solved "partially" because it appears not to be a universal working intent-filter.
How can I find a "all Android versions" working way of registering a custom file type and let me know if there is any possibility that registration is automatically done so whenever you see a .aw file in explorer -or wherever- your icon appears and your app opens the file.
This is my intent-filter in manifest.xml
<intent-filter
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="application/aw"
android:scheme="content" />
</intent-filter>
And this is how I treat it in activity that will open the file:
private String[] getIntentExtras()
{
Intent intent = getIntent();
String fileContents = null;
String action = intent.getAction();
if(action!=null)
{
if (action.equals(Intent.ACTION_VIEW))
{
fileContents = AWImport.importData(intent);
if (fileContents.startsWith("whatever"))
{
fileContents = fileContents.replace("whatever", "");
}
else
{
showErrorOpeningFile();
return null;
}
}
}
else
...