【发布时间】:2021-08-09 10:23:41
【问题描述】:
我有这个意图过滤器可以在我的应用中打开扩展名为“custom”的文件:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.custom" />
<data android:pathPattern=".*\\..*\\.custom" />
<data android:pathPattern=".*\\..*\\..*\\.custom" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.custom" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.custom" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.custom" />
</intent-filter>
从 Telegram 聊天中打开文件时效果也很好。
如何从任何地方打开我的自定义文件?
UPD
我为测试添加了 pdf mime-type。它从任何地方打开 pdf 文件。这是我得到的意图:
- 下载文件夹(使用自定义扩展名):
Intent { act=android.intent.action.VIEW dat=content://com.google.android.apps.nbu.files.provider/1/file:///storage/emulated/0/Download/Untitled.pdf typ=application/pdf flg=0x13000001 cmp=team.sls.testapp/.ActivityMain } - 用于电报(与自定义扩展一起使用):
Intent { act=android.intent.action.VIEW dat=content://org.telegram.messenger.provider/media/Telegram/Telegram Documents/2_5276292126848585208.pdf typ=application/pdf flg=0x13000001 cmp=team.sls.testapp/.ActivityMain } - 第二张图片中的下载文件夹(不适用于自定义扩展):
Intent { act=android.intent.action.VIEW dat=content://com.google.android.apps.nbu.files.provider/2/1863 typ=application/pdf flg=0x13000001 cmp=team.sls.testapp/.ActivityMain } - 用于从通知面板从下载管理器打开(不适用于自定义扩展):
Intent { act=android.intent.action.VIEW dat=content://com.android.providers.downloads.documents/document/1508 typ=application/pdf flg=0x13000003 cmp=team.sls.testapp/.ActivityMain }
【问题讨论】:
标签: android android-intent android-manifest intentfilter