gonzobrains
gonzobrains

Reputation: 8036

Android WebView needs to launch specific URLs in separate browser

I have made an app that uses a WebView to view a mobile website. The mobile website displays a "back" button within the WebView for pages served by its web server, but certain pages display links that navigate to external websites. I would like to display a "back" button on those pages to get back to the original web server, but if this is not possible I would like to launch these external sites in the standard browser in such a way that the user can still navigate the original site in the WebView using the "back" button the mobile site contains.

As it stands, my app cannot navigate back to the mobile site once a user clicks one of these "external" links because those sites do not display a back button to get back to the mobile app.

Upvotes: 1

Views: 464

Answers (1)

Paresh Mayani
Paresh Mayani

Reputation: 128428

You can implement WebViewClient for your WebView.

You can refer WebView for the example for the same.

For example:

 webview.setWebViewClient(new WebViewClient() {
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
     Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
   }
 });

 webview.loadUrl("http://developer.android.com");

Upvotes: 1

Related Questions