【问题标题】:Intent filter for custom pathPattern自定义 pathPattern 的意图过滤器
【发布时间】: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


    【解决方案1】:

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      相关资源
      最近更新 更多