Code example for WebView: Displaying web pages

Methods: getSettingsloadUrlsetWebChromeClientsetWebViewClient

0
 
	WebView webview;
	 
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		webview = new WebView(this);
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		setContentView(webview);
		setProgressBarVisibility(true);
		 
		if (icicle != null) {
			webview.restoreState(icicle);
		} else { 
			webview.getSettings().setJavaScriptEnabled(true);
			webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
			 
			final Activity activity = this;
			webview.setWebChromeClient( new WebChromeClient() {
				@Override 
				public void onProgressChanged(WebView view, int newProgress) {
					// TODO Auto-generated method stub 
					activity.setProgress(newProgress * 100);
				} 
			}); 
			 
			webview.setWebViewClient( new WebViewClient() {
				//private ProgressDialog dialog; 
				@SuppressWarnings("unused") 
				public void onErrorRecieved(WebView view, int errorCode, String description, String failingUrl) {
					Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
				}			 
			});  
			 
			webview.loadUrl(getIntent().getStringExtra("link"));
		} 
	} 
	 
	/* (non-Javadoc) 
	 * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)