意图过滤器匹配时,我测试,但不是当我按照链接
问题描述:
我看过很多“这是你如何做意图”的问题,我必须要失去一些明显的东西。意图过滤器匹配时,我测试,但不是当我按照链接
我有一个应用程序,当你浏览时,它应该监视并拦截一个特定的链接。当我生成一个测试意图并使用queryIntentActivities检查分辨率时,它匹配。但是,当我浏览到带有该链接的页面并点击该页面时,浏览器乐意继续关注该链接,而不是提供预期的弹出窗口。
代码来测试目的:
private Intent makeTestIntent() {
Intent testIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://my.machine.com/WebAppName/connect.link"));
testIntent.setFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
return testIntent;
}
public boolean testHomeIntent() {
Intent testIntent = makeTestIntent();
List<ResolveInfo> resolution = getPackageManager().queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
// I test by adding a breakpoint here and looking at the resolution list. The return value is irrelevant.
return true;
}
当我运行此,分辨率列表中有三项:我的活动,股票浏览器,而Firefox,都在优先级0与ISDEFAULT假。正如我所说,但是,当我访问具有相同链接的网页时,我的活动没有出现。它只是不断浏览。舱单
相关部分:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.package.name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_label" >
... other activities removed for brevity
<activity
android:name="com.my.package.name.ConnectActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/set_link_name">
<intent-filter>
<data android:scheme="http"
android:host="my.machine.name"
android:path="/WebAppName/connect.link" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
希望我没有在取出应用程序的名称 - 特定部分介绍了错别字太多。我还检查了没有任何应用程序已设置为默认情况下获得此意图。无论如何,这应该显示在测试解析器中,对吗?
请注意,我没有在这里使用webview - 我希望用户能够拥有自己的浏览器。
答
答案原来是“卸载Firefox”。或者至少停止使用它。
此时,Firefox将保留在浏览器中而不是提供其他选项。
https://bugzilla.mozilla.org/show_bug.cgi?id=653833 - 它标志着固定的,但看看评论36和37
当我从Firefox切换回它的表现如我所料的原生浏览器。