My app can open the following file formats:
I'm trying to set up properly my intent filters so that my app is proposed when trying to open one of these file types, through the following schemes:
I would expect the following filter to catch all cases (except files with dots in the name, but that's another problem):
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="content" />
<data android:pathPattern=".*\\.kml" />
<data android:pathPattern=".*\\.kmz" />
<data android:pathPattern=".*\\.gpx" />
<data android:mimeType="application/vnd.google-earth.kml+xml" />
<data android:mimeType="application/vnd.google-earth.kmz" />
<data android:mimeType="application/gpx+xml" />
</intent-filter>
But if the file explorer does not set properly the GPX content type, GPX files are not recognized (even though they are properly named, with ".gpx" extension).
Does someone know what's the problem?
So here is what I ended up with:
<!--Mime type set -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="content" />
<!-- Valid mime types -->
<data android:mimeType="application/vnd.google-earth.kml+xml" />
<data android:mimeType="application/vnd.google-earth.kmz" />
<data android:mimeType="application/gpx+xml" />
<!-- Invalid mime types used by some bad software -->
<data android:mimeType="application/kml" />
<data android:mimeType="application/kmz" />
<data android:mimeType="application/gpx" />
<data android:mimeType="application/kml+xml" />
<data android:mimeType="application/kmz+xml" />
<data android:mimeType="application/vnd.google-earth.kml" />
<data android:mimeType="application/vnd.google-earth.gpx" />
<data android:mimeType="application/vnd.google-earth.kmz+xml" />
<data android:mimeType="application/vnd.google-earth.gpx+xml" />
<data android:mimeType="text/kml" />
<data android:mimeType="text/kmz" />
<data android:mimeType="text/gpx" />
<data android:mimeType="text/kml+xml" />
<data android:mimeType="text/kmz+xml" />
<data android:mimeType="text/gpx+xml" />
<data android:mimeType="text/xml+kml" />
<data android:mimeType="text/xml+kmz" />
<data android:mimeType="text/xml+gpx" />
</intent-filter>
<!-- Mime type not set but valid extensions -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="content" />
<data android:host="*" />
<data android:pathPattern="/.*..*..*..*..*\\.gpx" />
<data android:pathPattern="/.*..*..*..*..*\\.kml" />
<data android:pathPattern="/.*..*..*..*..*\\.kmz" />
<data android:pathPattern="/.*..*..*..*\\.gpx" />
<data android:pathPattern="/.*..*..*..*\\.kml" />
<data android:pathPattern="/.*..*..*..*\\.kmz" />
<data android:pathPattern="/.*..*..*\\.gpx" />
<data android:pathPattern="/.*..*..*\\.kml" />
<data android:pathPattern="/.*..*..*\\.kmz" />
<data android:pathPattern="/.*..*\\.gpx" />
<data android:pathPattern="/.*..*\\.kml" />
<data android:pathPattern="/.*..*\\.kmz" />
<data android:pathPattern="/.*\\.gpx" />
<data android:pathPattern="/.*\\.kml" />
<data android:pathPattern="/.*\\.kmz" />
</intent-filter>
<!-- Invalid mime type but valid extensions -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="content" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern="/.*..*..*..*..*\\.gpx" />
<data android:pathPattern="/.*..*..*..*..*\\.kml" />
<data android:pathPattern="/.*..*..*..*..*\\.kmz" />
<data android:pathPattern="/.*..*..*..*\\.gpx" />
<data android:pathPattern="/.*..*..*..*\\.kml" />
<data android:pathPattern="/.*..*..*..*\\.kmz" />
<data android:pathPattern="/.*..*..*\\.gpx" />
<data android:pathPattern="/.*..*..*\\.kml" />
<data android:pathPattern="/.*..*..*\\.kmz" />
<data android:pathPattern="/.*..*\\.gpx" />
<data android:pathPattern="/.*..*\\.kml" />
<data android:pathPattern="/.*..*\\.kmz" />
<data android:pathPattern="/.*\\.gpx" />
<data android:pathPattern="/.*\\.kml" />
<data android:pathPattern="/.*\\.kmz" />
</intent-filter>
Seems to be working on all the file manager I tested (FX, ES, Astro, File Commander).
(For those wondering about the weird path patterns see pathPattern to match file extension does not work if a period exists elsewhere in the file name?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With