Code example for WebView: Displaying web pages

Methods: addJavascriptInterfacegetSettingsloadUrlsetWebViewClient, getContext

0
		this._processDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		this._processDialog.setMessage("载入中...");
 
		_webView = (WebView) findViewById(R.id.webView_content);
 
		WebSettings settings = this._webView.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setSaveFormData(false);
		settings.setSavePassword(false);
		settings.setSupportZoom(false);
		settings.setDomStorageEnabled(true);
 
		this._webView.setWebViewClient(this._webClient);
		this._webView.addJavascriptInterface(this._webInterface, "interface");
 
		// 提取cookie 
		Bundle bundle = this.getIntent().getExtras();
		String cookie = bundle.get("cookie").toString();
		// 设置cookie 
		CookieSyncManager syncManager = CookieSyncManager
				.createInstance(this._webView.getContext());
		CookieManager cookieManager = CookieManager.getInstance();
		cookieManager.setAcceptCookie(true);
		cookieManager.removeSessionCookie();
		cookieManager.setCookie("http://" + _settings.get("address", ""),
				cookie);
		syncManager.sync();
		// 加载主页 
		navigate_remote(HOME_URL);
	} 
 
	@SuppressWarnings("unused") 
	private void navigate_local(String url) {
		this._webView.loadUrl(LOCAL_BASE + url);
	} 
 
	private void navigate_remote(String url) {
		String re_addr = _settings.get("address", "10.250.62.6");
		if (!re_addr.startsWith("http://")) {
			re_addr = "http://" + re_addr;
		} 
		final String address = re_addr;
		final String abs_url = address + url;
		if (Network.isNetworkAvailable(this)) {
			_webView.loadUrl(abs_url);
		} else { 
			Toast.makeText(getApplicationContext(), "请连接网络", Toast.LENGTH_SHORT)
					.show();
		} 
 
Connect your IDE to all the code out there  Get Codota for Java