Android Web浏览器应用程序-如何拦截URL意图?
我有一个自定义ROM,除了WebView浏览器检测仪之外,没有默认浏览器。我已经开发了自己的web浏览器应用程序(webviewclient活动),并将其安装在手机中。现在,我希望无论用户在手机中单击什么URL,我的浏览器应用程序都会截取并加载此URL。下面是我在intent_filter中使用的内容Android Web浏览器应用程序-如何拦截URL意图?,android,android-intent,android-activity,android-manifest,intentfilter,Android,Android Intent,Android Activity,Android Manifest,Intentfilter,我有一个自定义ROM,除了WebView浏览器检测仪之外,没有默认浏览器。我已经开发了自己的web浏览器应用程序(webviewclient活动),并将其安装在手机中。现在,我希望无论用户在手机中单击什么URL,我的浏览器应用程序都会截取并加载此URL。下面是我在intent_filter中使用的内容 <intent_filter> <action android:name="android.intent.action.VIEW"/>
<intent_filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent_filter>
但它不工作,仍然
WebView
browser Tester应用程序启动和加载链接。有人能告诉我如何将我的应用程序设置为默认浏览器应用程序,或者在单击任何URL
时使用任何有助于启动此活动的特殊意图吗 为此,您必须确定浏览器
应用程序的启动活动
,如下所示:
Intent intent = new Intent();
intent.setComponent(new ComponentName("/*Pass your browser package*/","com.google.android.browser.BrowserActivity /*And pass Browser Activity*/"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
链接上已提供答案请尝试添加两个意向筛选器
<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="http"
android:host="*"/>
</intent-filter>
<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="https"
android:host="*" />
</intent-filter>