Code example for WebView: Displaying web pages

Methods: getSettingsloadUrlrestoreStatesetWebChromeClient

0
        // createInstance() needs to be called first. 
        CookieSyncManager.createInstance(this);
 
        requestWindowFeature(Window.FEATURE_PROGRESS);
         
        mWebView = new WebView(this);
        setContentView(mWebView);
         
        // Setup callback support for title and progress bar 
        mWebView.setWebChromeClient( new WebChrome() );
         
        // Configure the webview 
        WebSettings s = mWebView.getSettings();
        s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        s.setUseWideViewPort(true);
        s.setSavePassword(false);
        s.setSaveFormData(false);
        s.setBlockNetworkLoads(true);
         
        // Javascript is purposely disabled, so that nothing can be  
        // automatically run. 
        s.setJavaScriptEnabled(false);
         
        // Restore a webview if we are meant to restore 
        if (savedInstanceState != null) {
            mWebView.restoreState(savedInstanceState);
        } else { 
            // Check the intent for the content to view 
            Intent intent = getIntent();
            if (intent.getData() != null) {
                Uri uri = intent.getData();
                String contentUri = "file".equals(uri.getScheme())
                        ? FileContentProvider.BASE_URI + uri.getEncodedPath()
                        : uri.toString();
                String intentType = intent.getType();
                if (intentType != null) {
                    contentUri += "?" + intentType;
                } 
                mWebView.loadUrl(contentUri);
            } 
        } 
    } 
     
    @Override