Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. WebAppInterface wai = new WebAppInterface(this, this);
  2. myWebView.addJavascriptInterface(wai, "Android");
  3. myWebView.loadUrl("http://192.168.2.246/abhishek/test/");
  4.  
  5. class WebAppInterface {
  6. Context mContext;
  7. MainActivity parent;
  8.  
  9. /** Instantiate the interface and set the context */
  10. WebAppInterface(Context c, MainActivity parent) {
  11. mContext = c;
  12. this.parent = parent;
  13. }
  14.  
  15. @JavascriptInterface
  16. public void setHeading(String heading) {
  17. Toast.makeText(mContext, "Setting heading to " + heading, Toast.LENGTH_SHORT).show();
  18. }
  19. }
  20.  
  21. function setHeading(heading) {
  22. console.log("setting heading...");
  23. // Android callback
  24. if(typeof Android !== 'undefined'){
  25. Android.setHeading(heading);
  26. }
  27. if(typeof Android == 'undefined') {
  28. console.log("undefined!!");
  29. }
  30. }
  31.  
  32. public static final native void setAppHeading(String heading) /*-{
  33. $wnd.setHeading(heading);
  34. }-*/;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement