自定义 pathPattern 的意图过滤器

时间:2021-05-20 07:20:38

标签: android android-intent android-manifest intentfilter

我有这个意图过滤器可以在我的应用程序中打开扩展名为“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>

在这种情况下,文件打开良好: enter image description here

但在这种情况下它不会打开: enter image description here

从 Telegram 聊天打开文件时也能很好地工作。

如何从任何地方打开我的自定义文件?

UPD

我为测试添加了 pdf mime 类型。它可以从任何地方打开 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 }
  • 对于 Telegram(适用于自定义扩展):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 }
  • 从通知面板从 Dowdload 管理器打开(不适用于自定义扩展):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 }

1 个答案:

答案 0 :(得分:0)

<块引用>

如何从任何地方打开我的自定义文件?

无法从任何地方打开自定义文件。

@CommonsWare 帮助我找出了another question 中的原因。

问题在于 Uri 中的 Intents 值没有文件扩展名。

有哪些替代方案?我们可以使用标准的 application/{whatever} mime-type 在我们的应用程序中打开文件。但是我们必须在文件资源管理器中选择“打开方式...”菜单项。

相关问题