我有这个意图过滤器可以在我的应用程序中打开扩展名为“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 类型。它可以从任何地方打开 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 }
答案 0 :(得分:0)
如何从任何地方打开我的自定义文件?
无法从任何地方打开自定义文件。
@CommonsWare 帮助我找出了another question 中的原因。
问题在于 Uri
中的 Intents
值没有文件扩展名。
有哪些替代方案?我们可以使用标准的 application/
{whatever} mime-type 在我们的应用程序中打开文件。但是我们必须在文件资源管理器中选择“打开方式...”菜单项。