Code example for WebView: Displaying web pages

Methods: addJavascriptInterfacegetSettingsloadUrlsetBackgroundColorsetWebChromeClientsetWebViewClient, requestFocus, setOnKeyListener, setOverScrollMode

0
		mChromeClient = new GDWebChromeClient(this);
		setContentView(R.layout.webview);
 
		mWebView = (WebView) findViewById(R.id.web_view);
	 
		mWebView.requestFocus(View.FOCUS_DOWN);
 
		mWebView.setBackgroundColor(Color.TRANSPARENT);
		mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);
		 
		WebSettings settings = mWebView.getSettings();
		settings.setJavaScriptEnabled(true);
 
		mWebView.addJavascriptInterface(new JavaScriptInterface(this),
				"Utility"); 
 
		if (settings.getBlockNetworkLoads()) {
			settings.setBlockNetworkLoads(false);
			Log.d(TAG, "setBlockNetworkLoads false");
		} 
 
		if (settings.getBlockNetworkImage()) {
			settings.setBlockNetworkImage(false);
			Log.d(TAG, "setBlockNetworkImage false");
		} 
 
		mWebView.getSettings().setCacheMode(WebSettings.LOAD_NORMAL);
		mWebView.getSettings().setAllowContentAccess(true);
		mWebView.getSettings().setAllowFileAccess(true);
		mWebView.getSettings().setAppCacheEnabled(true);
		mWebView.getSettings().setAppCacheMaxSize(1024*1024*100);
		mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
		 
		File cacheDir = getCacheDir();
		String webCacheDir = cacheDir.getAbsolutePath() + "/webcache";
		File webCache = new File(webCacheDir);
		 
		if (!webCache.exists()) {
			webCache.mkdirs();
		} 
		 
		mWebView.getSettings().setAppCachePath(webCacheDir);
		mWebView.getSettings().setDatabaseEnabled(true);
 
		String webDatabaseDir = cacheDir.getAbsolutePath() + "/webdatabase";
		File webDatabase = new File(webDatabaseDir);
		 
		if (!webDatabase.exists()) {
			webDatabase.mkdirs();
		} 
		mWebView.getSettings().setDatabasePath(webDatabaseDir);
		mWebView.getSettings().setEnableSmoothTransition(true);
		//mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); 
		mWebView.getSettings().setLightTouchEnabled(false);
		mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
		mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.NORMAL);
		//mWebView.getSettings().setSupportMultipleWindows(true); 
		mWebView.getSettings().setUseWideViewPort(true);
		// 
		// mWebView.getSettings().setHardwareAccelSkiaEnabled(true); 
		// 
		mWebView.setWebViewClient(mWVClient);
		mWebView.setWebChromeClient(mChromeClient);
//		mWebView.setWebViewClient(new WebViewClient()); 
//		mWebView.setWebChromeClient(new WebChromeClient()); 
 
		mWebView.setOnKeyListener(new View.OnKeyListener() {
 
			@Override 
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				Log.d(TAG, "onKey " + keyCode);
				boolean ret = false;
				int action = event.getAction();
				if (action == KeyEvent.ACTION_DOWN) {
					switch (keyCode) {
//					case KeyEvent.KEYCODE_DPAD_LEFT: { 
//						 
//						break; 
//					} 
//					case KeyEvent.KEYCODE_DPAD_RIGHT: 
//						break; 
//					 
//					 
					case KeyEvent.KEYCODE_ESCAPE:
					case KeyEvent.KEYCODE_BACK: {
						ret = true;
						activity.onBackPressed();
						break; 
					} 
					default: 
						break; 
					} 
				} 
				return ret;
			} 
		}); 
 
		Intent intent = getIntent();
		String url = intent.getStringExtra("url");
 
		Log.d(TAG, "url = " + url);
		mWebView.loadUrl(url);
		//loadPageDelay(url); 
	} 
 
	private static final int MSG_BACKEVENT = 0;
	private static final int  MSG_LOADPAGE = 1;
Connect your IDE to all the code out there  Get Codota for Java