Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WebAppInterface wai = new WebAppInterface(this, this);
- myWebView.addJavascriptInterface(wai, "Android");
- myWebView.loadUrl("http://192.168.2.246/abhishek/test/");
- class WebAppInterface {
- Context mContext;
- MainActivity parent;
- /** Instantiate the interface and set the context */
- WebAppInterface(Context c, MainActivity parent) {
- mContext = c;
- this.parent = parent;
- }
- @JavascriptInterface
- public void setHeading(String heading) {
- Toast.makeText(mContext, "Setting heading to " + heading, Toast.LENGTH_SHORT).show();
- }
- }
- function setHeading(heading) {
- console.log("setting heading...");
- // Android callback
- if(typeof Android !== 'undefined'){
- Android.setHeading(heading);
- }
- if(typeof Android == 'undefined') {
- console.log("undefined!!");
- }
- }
- public static final native void setAppHeading(String heading) /*-{
- $wnd.setHeading(heading);
- }-*/;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement