单击android webview中的链接时启动打开浏览器

时间:2015-01-06 01:38:13

标签: java android browser webview

我试图将我的android webview内的链接加载到设备上可用的其中一个网络浏览器中。发生的事情是它只是加载webview中的链接。如何在我的应用程序的webview之外加载链接?

我需要做的工作是:

<a href="http://www.testsite.com/linka">Forgot your password?</a>

当我点击它没有任何反应时,我需要它来调用设备的默认Web浏览器。

我的shouldOverrideUrlLoading目前用于检查网址并加载另一项活动,如果它相等:

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;
    }
}

1 个答案:

答案 0 :(得分:3)

要在浏览器中打开网址,只需使用以下代码:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
相关问题