Code example for WebView: Displaying web pages

Methods: addJavascriptInterfacegetSettingsloadUrlsetScrollBarStylesetWebChromeClientsetWebViewClient

0
	 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        webview = new WebView(this);
        setContentView(webview);
         
        initControls(); 
    } 
 
    /** 
     * Initializes the WebView and defines the WebClient behavior. 
     */ 
	private void initControls() { 
        String path = String.format(EndpointAuthNew, AppBlade.appInfo.Token);
        final String authUrl = WebServiceHelper.getUrl(path);
        jsInterface = new AuthJavascriptInterface(RemoteAuthorizeActivity.this);
 
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webview.addJavascriptInterface(jsInterface, "Android");
        webview.setWebChromeClient(new WebChromeClient() {
        	@Override 
			public void onProgressChanged(WebView view, int progress) {
        		// Activities and WebViews measure progress with different scales. 
        		// The progress meter will automatically disappear when we reach 100% 
        		setProgress(progress * 100);
        	} 
        }); 
 
        webview.setWebViewClient(new WebViewClient() {
			@Override 
			public void onLoadResource(WebView view, String url) {
				super.onLoadResource(view, url);
			} 
			@Override 
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
				if(progress != null && progress.isShowing())
					progress.dismiss();
			} 
			@Override 
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);
				if(progress == null || !progress.isShowing())
					progress = ProgressDialog.show(RemoteAuthorizeActivity.this, null, "loading...");
			} 
        }); 
         
		webview.loadUrl(authUrl);
	} 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE