Code example for WebView: Displaying web pages

Methods: getSettingsloadUrlsetWebChromeClientsetWebViewClient

0
		final Intent intent = this.getIntent();
		initializeWebView(intent);
	} 
 
	private void initializeWebView(Intent intent) {
		WebView webView = new WebView(this);
		this.setContentView(webView);
		WebSettings webSettings = webView.getSettings();
 
		webSettings.setJavaScriptEnabled(true);
 
		webSettings.setSupportZoom(true);
		webSettings.setBuiltInZoomControls(true);
		webSettings.setUseWideViewPort(true);
		webView.setWebViewClient(new WebViewClient() {
			@Override 
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				Activity a = (Activity) view.getContext();
				Toast.makeText(a, "MRAID error: " + description,
						Toast.LENGTH_SHORT).show();
			} 
 
			@Override 
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				if (url == null)
					return false; 
 
				Uri uri = Uri.parse(url);
				String host = uri.getHost();
 
				if (url.startsWith("market:") || url.startsWith("tel:")
						|| url.startsWith("voicemail:")
						|| url.startsWith("sms:") || url.startsWith("mailto:")
						|| url.startsWith("geo:")
						|| url.startsWith("google.streetview:")
						|| "play.google.com".equals(host)
						|| "market.android.com".equals(host)) {
					try { 
						startActivity(new Intent(Intent.ACTION_VIEW, Uri
								.parse(url)));
					} catch (ActivityNotFoundException exception) {
					} 
 
					finish();
					return true; 
				} 
				view.loadUrl(url);
				return true; 
			} 
		}); 
 
		webView.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int progress) {
				Activity a = (Activity) view.getContext();
				a.setTitle("Loading...");
				a.setProgress(progress * 100);
				if (progress == 100)
					a.setTitle(view.getUrl());
			} 
		}); 
		webView.loadUrl(intent.getStringExtra(Const.REDIRECT_URI));
	} 
 
}