Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Complete action using" when trying to load in a WebView

I'm testing the built-in WebView in the Android apps. My problem is that the following code

WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl("http://google.com");

triggers an intent (sugesting the installed browsers for opening the web) instead of open it in the built-in WebView. What should I do for avoiding that?

like image 771
Addev Avatar asked Apr 19 '12 10:04

Addev


People also ask

What permission does WebView require to work?

Android Permissionsxml file is necessary for an Activity to load a web page into a WebView.

How do you override a WebView?

If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.

What are the features provided by WebView?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.

What is a WebView component?

Android System WebView is a system component for the Android operating system (OS) that enables Android apps to display web content directly inside an application.


1 Answers

WebView mWebView= (WebView) findViewById(R.id.webView1);
mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

mWebView.loadUrl("http://google.com");

This won't open other broweser. Have reference here from DEVELOPER's SITE.

like image 132
Bhavin Avatar answered Sep 20 '22 00:09

Bhavin