Share Coding

Tutorials, Problems, Stuffs …

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');
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: