Last active
October 17, 2017 01:26
-
-
Save junsuk5/610ce65a0f19fdbbd2b477fc1fd64c4f to your computer and use it in GitHub Desktop.
Java와 Javascript간 통신
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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