我的应用可以打开以下文件格式:
我尝试正确设置我的意图过滤器,以便在尝试通过以下方案打开其中一种文件类型时提出我的应用:
我希望以下过滤器可以捕获所有情况(除了名称中包含点的文件,但这是另一个问题):
<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>
但是如果文件资源管理器未正确设置GPX内容类型,则无法识别GPX文件(即使它们已正确命名,使用&#34; .gpx&#34;扩展名)。
有人知道问题是什么吗?
答案 0 :(得分:5)
所以这就是我最终的结果:
<!--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>
似乎正在处理我测试过的所有文件管理器(FX,ES,Astro,File Commander)。
(对于那些对奇怪路径模式感到疑惑的人,请参阅pathPattern to match file extension does not work if a period exists elsewhere in the file name?)