-1

its an app of view wordpress site via json api but the problem is when i click on link its open in the app i want to open it on the externel browser like chrome ... ect

this is the code of 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;
}
}

i want to tell me what i will change on it

Serg Chernata
  • 12,280
  • 6
  • 32
  • 50

1 Answers1

0

if you want to open the link in a browser like chrome, delete all that code and just open your link in externel browser like this:

 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)));
    }
Yessine Mahdouani
  • 1,225
  • 12
  • 24