自定义 pathPattern 的意图过滤器 [英] Intent filter for custom pathPattern

查看:64
本文介绍了自定义 pathPattern 的意图过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个意图过滤器来打开扩展名为自定义"的文件;在我的应用中:

I have this intent filter to open files with extension "custom" in my app:

<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>

在这种情况下,文件打开良好:

In this case file opens well:

但在这种情况下它不会打开:

But in this case it doesn't open:

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

Also it works well when opening file from Telegram chat.

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

How can I open my custom files from anywhere?

UPD

我为测试添加了 pdf mime 类型.它可以从任何地方打开 pdf 文件.这是我得到的意图:

I've added pdf mime-type for tests. It opens pdf files from everywhere. Here are the intents I got:

  • 下载文件夹(适用于自定义扩展):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.pdftyp=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 }

推荐答案

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

How can I open my custom files from anywhere?

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

There is no way to open custom files from anywhere.

@CommonsWare 帮助我找出了我的 另一个问题.

@CommonsWare helped me to figure out the reason in my another question.

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

The problem is that Uri values in Intents do not have file extensions.

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

What are the alternatives? We can use standard application/{whatever} mime-type to open files in our application. But we have to select "Open with..." menu item in file explorer then.

这篇关于自定义 pathPattern 的意图过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆