Skip to content

Instantly share code, notes, and snippets.

@junsuk5
Last active October 17, 2017 01:26
Show Gist options
  • Select an option

  • Save junsuk5/610ce65a0f19fdbbd2b477fc1fd64c4f to your computer and use it in GitHub Desktop.

Select an option

Save junsuk5/610ce65a0f19fdbbd2b477fc1fd64c4f to your computer and use it in GitHub Desktop.
Java와 Javascript간 통신
# Android
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new JsInterface(), "androidJs");
public class JsInterface {
@JavascriptInterface
public void callback(String message) {
// 자바스크립트에서 호출 됨
}
}
# Javascript
<script>
function clicked() {
// alert('hello');
androidJs.callback('hello');
}
</script>
<button onclick="clicked()">눌러라</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment