Android WebView http链接打开Chrome浏览器,其中2个标签位于同一个网址

时间:2012-10-26 11:36:33

标签: android webview

我的应用程序中有一个显示本地html文件的WebView。其中有PDF文件的链接,我正在处理shouldOverrideUrlLoading()方法,但是通过这样做,页面上的http://链接现在正在WebView中加载,而不是在设备的浏览器中加载。 / p>

下面的代码识别pdf文件,这很好用,但是当我点击外部网址时,它会在Chrome浏览器中打开两个相同网址的标签。我怎么才能打开那个?

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.contains(".pdf")) {
            // Remove the file:///android_asset/ text in url
            String tmpUrl = url.replace("file:///android_asset/", "");
            PdfHandler pdf = new PdfHandler(mContext);
            pdf.openPdf(tmpUrl);
            return true;
        }
        else{
            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    }
}

由于

1 个答案:

答案 0 :(得分:0)

答案是将此标志添加到启动浏览器的Activity中:

intent.putExtra(Browser.EXTRA_APPLICATION_ID,mContext.getPackageName());

这会强制浏览器始终在我的应用程序创建的选项卡中打开链接