[英]Intent filter works on emulator but not on device
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.我正在创建一个自定义意图过滤器,当我点击具有特定文件扩展名(在这种情况下为
.myextension
)的文件时,它将打开我的应用程序。意图过滤器如下。 This currently works perfectly every time I open a .myextension
file from my emulator.目前,每次我从模拟器打开
.myextension
文件时,这都能完美运行。 However, when I try it from my device, it no longer works.但是,当我从我的设备上尝试它时,它不再有效。
On my device, when I tap a .myextension
file in the Files browser app, I see Unable to preview file.
在我的设备上,当我在文件浏览器应用程序中点击
.myextension
文件时,我看到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.
我尝试从多个位置(文件应用程序、GDrive、下载文件夹、Slack/Gmail、内部存储和 SDCard)打开文件。我在模拟器和设备上都使用 Android 10。
<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>
I've also tried replacing that data
tag/adding a second tag with this block but it doesn't seem to help:我也试过用这个块替换那个
data
标签/添加第二个标签,但它似乎没有帮助:
<data
android:scheme="file"
android:mimeType="*/*"
android:host="*"
android:pathPattern=".*\\.myextension" />
Am I missing something obvious?我错过了一些明显的东西吗? Any help would be greatly appreciated.
任何帮助将不胜感激。 Thanks!
谢谢!
This currently works perfectly every time I open a.myextension file from my emulator.
目前,每次我从模拟器打开 a.myextension 文件时,这都能完美运行。
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.
但是,当我从我的设备上尝试它时,它不再有效。
A content
Uri
is not required to have a file extension, just as an https
URL is not required to have a file extension. content
Uri
不需要具有文件扩展名,就像https
URL 不需要具有文件扩展名一样。 Much of the time, a content
Uri
will not have a file extension, and such a Uri
will not match your <intent-filter>
.很多时候,
content
Uri
不会有文件扩展名,这样的Uri
不会匹配您的<intent-filter>
。
ACTION_VIEW
is mostly for files with a widely-recognized MIME type. ACTION_VIEW
主要用于具有广泛认可的 MIME 类型的文件。
I've also tried replacing that data tag/adding a second tag with this block but it doesn't seem to help
我也试过用这个块替换那个数据标签/添加第二个标签,但它似乎没有帮助
file
Uri
values have been generally banned since Android 7.0.自 Android 7.0 以来,
file
Uri
值通常已被禁止。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:pathPattern=".*\\.myextension" />
<data android:pathPattern="/*.*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:pathPattern="/*.*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.myextension" />
<data android:host="*" />
</intent-filter>
Though it doesnt work in some of the file managers Better first try in ESExplorer.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.