我正在尝试将我的android webview内的链接加载到设备上可用的一种网络浏览器中。发生的是,它只是将链接加载到了webview中。如何使链接加载到应用程序的Web视图之外?
我需要工作的链接是这样的:
<a href="http://www.testsite.com/linka">Forgot your password?</a>
当我单击它时,没有任何反应,我需要它来调用设备的默认Web浏览器。
我的shouldOverrideUrlLoading当前用于检查URL并加载另一个相等的活动:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("extraData", "the urls"+Uri.parse(url).getPath());
if (Uri.parse(url).getPath().equals("/qr_code")) {
progress.setVisibility(View.GONE);
Intent intent = new Intent(getApplicationContext(),QRActivity.class);
startActivityForResult(intent, 1);
setContentView(R.layout.activity_qr);
//return true;
}
if(Uri.parse(url).getPath().equals("/linka")){
return true;
}
return false;
}
更新:现在可以正常工作了,但是由于某种原因,我当前的webView仍然运行该链接,因此页面加载到了单击的链接上
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("extraData", "the urls"+Uri.parse(url).getPath());
if (Uri.parse(url).getPath().equals("/TMMobile/Main/qr_code")) {
//return true;
}
if(Uri.parse(url).getPath().equals("/linka")){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://testdomain/RecoverPassword.aspx"));
startActivity(browserIntent);
}
return false;
}
}
要在浏览器中打开URL,只需使用以下代码即可:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句