Share Coding

Tutorials, Problems, Stuffs …

Tag Archives: javascript

Return value from JavaScript to Android Webview

WebView WebView1 = new WebView(this);
WebView1.getSettings().setJavaScriptEnabled(true);
WebView1.setWebChromeClient(MyWebChromeClient);
....
private WebChromeClient MyWebChromeClient = new WebChromeClient() {
	@Override
	public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
		try {
			// "message" is the text shown in alert box
			Log.v("message",java.net.URLDecoder.decode(message, "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return true;
	}
};
//If the "message" text is garbled, you can try to add this on php header: ini_set('default_charset','utf-8');