问题
我有一个 zip 文件,但具有自定义文件扩展名 xyz。 我希望我的应用程序只能打开自定义文件扩展名为 xyz 的文件,来自:
- Gmail,
-
Open with
从 android 文件资源管理器, -
Share via
来自 android 文件资源管理器。
我已经尝试过的
我最好的办法是只使用 application/zip
的 mime 类型.但是,这也会打开文件扩展名为 .zip 的文件。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/zip" />
</intent-filter>
我试图添加一个 <data android:pathPattern=".*\\.xyz"/>
.但问题是,只要我不指定 android:scheme
,它就会被忽略。和 android:host
see here .
This attribute is meaningful only if the scheme and host attributes are also specified for the filter.
一旦我在下一个代码段中指定方案和主机,我什至无法使用我的应用程序打开任何文件:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="*" />
<data android:mimeType="application/zip" />
<data android:pathPattern=".*\\.xyz"/>
</intent-filter>
可能重复:
最佳答案
使用 application/octet-stream
而不是 application/zip
。贝娄对我有用:
<intent-filter tools:ignore="AppLinkUrlError"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:priority="50" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\.ext" />
<data android:pathPattern=".*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\.ext" />
</intent-filter>
关于java - 用于自定义文件类型的 Android Intent Filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63172852/