【问题标题】:i want to open links in externel browser not in the app help me [duplicate]我想在外部浏览器中打开链接而不是在应用程序中帮助我[重复]
【发布时间】:2017-05-27 00:10:54
【问题描述】:

它是一个通过 json api 查看 wordpress 站点的应用程序,但问题是当我点击它在应用程序中打开的链接时,我想在外部浏览器上打开它,比如 chrome ... ect

这是webview的代码

    // Get Web view
    mWebView = (WebView) rootView.findViewById(R.id.webView); //This is the id you gave to the WebView in the main.xml
    pBar = (ProgressBar) rootView.findViewById(R.id.pbLoader); //This is the id you gave to the WebView in the main.xml
    pBarText = (TextView) rootView.findViewById(R.id.pbLoaderText);

    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setAllowContentAccess(true);
    mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    mWebView.getSettings().setLoadsImagesAutomatically(true);
    mWebView.getSettings().setDefaultTextEncodingName("utf-8");
    mWebView.getSettings().setUseWideViewPort(true);
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setSupportZoom(true);       //Zoom Control on web (You don't need this //if ROM supports Multi-Touch
    mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM

    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        }
    });

    if (savedInstanceState == null) {
        if (getArguments().getString("httpURL") == null) {
            httpURL = null;
        } else {
            httpURL = getArguments().getString("httpURL");
        }
    } else {
        httpURL = (String) savedInstanceState.getSerializable("httpURL");
    }

    mWebView.loadUrl(httpURL);

    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            //Make the bar disappear after URL is loaded, and changes string to Loading...
            pBarText.setText("Loading...   (" + (progress) + "%)");
            pBar.setProgress(progress * 100); //Make the bar disappear after URL is loaded


            // Return the app name after finish loading
            if (progress == 100) {
                pBar.setVisibility(View.GONE);
                pBarText.setVisibility(View.GONE);
            }
        }
    });
    return rootView;
}
}

我想告诉我我会改变什么

【问题讨论】:

    标签: android browser


    【解决方案1】:

    如果您想在 chrome 等浏览器中打开链接,请删除所有代码,然后在外部浏览器中打开您的链接,如下所示:

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(your_link));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setPackage("com.android.chrome");
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            // Chrome browser presumably not installed so open the default browser
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(your_link)));
        }
    

    【讨论】:

    • 我明白我将删除我的问题中包含的完整代码。?
    猜你喜欢
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多