首页 > 解决方案 > Android Intent Filters - 专有文件类型的空白 mimeType

问题描述

我使用意图过滤器将我的应用程序与我的专有文件类型相关联,因此用户可以点击文件并在我的应用程序中打开它。直到最近我一直在使用基于文件名的一个:

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="*/*" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:host="*" />
<data android:pathPattern=".*\\.rhr" />

(加上 pathPattern 的其他变体以允许文件夹)

似乎从 Android 7 开始,应用程序无法共享 File URLs Official docs。没问题,我们可以使用 Mime 类型:

<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="content" />
<data android:mimeType="[???]" />

除了某些应用程序不发送 mime 类型。例如,三星我的文件应用程序发送一个空字符串作为 mime 类型。

我可以求助于使用“*/*”,但这肯定会惹恼人们。还有其他选择吗?

标签: androidandroid-intentandroid-manifest

解决方案


推荐阅读