我正在尝试将我的 android webview 中的链接加载到设备上可用的网络浏览器之一中。发生的事情是它只是加载 web View 中的链接。如何使链接在我的应用程序的 Web View 之外加载?
我需要工作的链接是这样的:
<a href="http://www.testsite.com/linka">Forgot your password?</a>
当我点击它时没有任何反应,我需要它来调用设备的默认网络浏览器。
我的shouldOverrideUrlLoading当前用于检查URL并加载另一个 Activity (如果相等):
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);
关于java - 单击 android webview 中的链接时启动打开的浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27790794/