意图过滤器可在模拟器上运行,但不能在设备上运行 [英] Intent filter works on emulator but not on device
问题描述
我正在创建一个自定义的意图过滤器,当我点击带有特定文件扩展名的文件(在本例中为.myextension
)时,它将打开我的应用程序.意图过滤器位于下面.当前,每次我从模拟器中打开.myextension
文件时,此方法均能完美运行.但是,当我从设备上尝试时,它不再起作用.
I'm creating a custom intent filter which will open my app when I tap a file with a certain file extension (.myextension
in this case.) The intent-filter is below. This currently works perfectly every time I open a .myextension
file from my emulator. However, when I try it from my device, it no longer works.
在设备上,当我在文件浏览器应用程序中点击.myextension
文件时,看到的是Unable to preview file.
,而不是自动打开该应用程序.我尝试从多个位置(文件应用程序,GDrive,下载文件夹,Slack/Gmail,内部存储和SDCard)打开文件.我在模拟器和设备上都使用了Android 10.
On my device, when I tap a .myextension
file in the Files browser app, I see Unable to preview file.
instead of automatically opening the app. I've tried opening the file from quite a few locations (Files app, GDrive, Downloads folder, Slack/Gmail, both internal storage and SDCard.) I'm using Android 10 on both my emulator and my device.
<intent-filter android:label="My App">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="content"
android:mimeType="*/*"
android:host="*"
android:pathPattern=".*\\.myextension" />
</intent-filter>
我也尝试过替换该data
标签/在此块中添加第二个标签,但这似乎无济于事:
I've also tried replacing that data
tag/adding a second tag with this block but it doesn't seem to help:
<data
android:scheme="file"
android:mimeType="*/*"
android:host="*"
android:pathPattern=".*\\.myextension" />
我缺少明显的东西吗?任何帮助将不胜感激.谢谢!
Am I missing something obvious? Any help would be greatly appreciated. Thanks!
推荐答案
每次我从模拟器中打开.myextension文件时,此功能目前都可以正常使用.
This currently works perfectly every time I open a .myextension file from my emulator.
它在很多时候都会失败,因为它并不是真正与仿真器或设备绑定在一起的.
It will fail much of the time, as it is not really tied to an emulator versus a device.
但是,当我从设备上尝试时,它不再起作用.
However, when I try it from my device, it no longer works.
不需要content
Uri
具有文件扩展名,就像https
URL不需要具有文件扩展名一样.在大多数情况下,content
Uri
将没有文件扩展名,而这样的Uri
将与您的<intent-filter>
不匹配.
A content
Uri
is not required to have a file extension, just as an https
URL is not required to have a file extension. Much of the time, a content
Uri
will not have a file extension, and such a Uri
will not match your <intent-filter>
.
ACTION_VIEW
主要用于具有公认的MIME类型的文件.
ACTION_VIEW
is mostly for files with a widely-recognized MIME type.
我也尝试过使用该块替换该数据标签/添加第二个标签,但这似乎无济于事
I've also tried replacing that data tag/adding a second tag with this block but it doesn't seem to help
从Android 7.0开始,
file
Uri
值通常被禁止.
file
Uri
values have been generally banned since Android 7.0.
这篇关于意图过滤器可在模拟器上运行,但不能在设备上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!