I have read several questions and answers about this (including this one), but most appear to be about older versions of Android and th file system is very different in Android 10. I have also tried to follow the 'App Links Assistant' in Android Studio (4.0.1) but that appers to be only for links from websites, and I wish to open my app from a file explorer. From what I have read, it looks as though my intent filter is correct:
<activity android:name=".OpenKMZ">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:host="*" />
<!-- <data android:mimeType="application/vnd.google-earth.kmz" /> -->
<data android:pathPattern=".*\\.kmz" />
</intent-filter>
</activity>
I have tried this intent filter with and without the mime type definition.
This is the code I have used to deal with the file when it is opened (so far it would just tell me it has found the file - I will add the rest later).
public class OpenKMZ extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
associateFile();
}
private void associateFile() {
Intent intent = getIntent();
String action = intent.getAction();
assert action != null;
if (action.compareTo(Intent.ACTION_VIEW) == 0) {
Toast.makeText(this,
"from file explorer ! ********************",
Toast.LENGTH_LONG).show();
String scheme = intent.getScheme();
ContentResolver resolver = getContentResolver();
assert scheme != null;
if (scheme.compareTo(ContentResolver.SCHEME_FILE) == 0) {
Uri uri = intent.getData();
assert uri != null;
Toast.makeText(this,
uri.toString(),
Toast.LENGTH_LONG).show();
String name = uri.getLastPathSegment();
}
}
}
}
but after installing the app, file explorers refuse to know what do do with .kmz files. I have tried ES file explorer on Android 8, and the built-in file explorer in Android 10. I have tried the intent filter included in MainActivity, as well as in a separate activity as shown here. Am I missing something fundamental, or is there a mistake with my code?