javascript - Calling an Android function from AngularJS controller -


I have a problem for which I need some help. I'm trying to call the Android function in my frontend using an angle controller, but I can not get it to work.

Main Activity:

@ Override Protected Zero (Bundle Saved Instantstate) {Super.New (Saved Instantstate); SetContentView (R.layout.activity_main); MWebView = (webview) Find VibibIID (RIDA activism_man_viewview); MWebView.setWebViewClient (new CustomWebViewClient ()); WebSites webSettings = mWebView.getSettings (); WebSettings.setJavaScriptEnabled (true); MWebView.addJavascriptInterface (new AngularGenfinder (this), "Android"); MWebView.loadUrl ("http://192.168.70.101:3000/"); }

AngularJSInterface:

  public class AngularJSInterface {reference mContext; Angular jsinterface (reference c) {amcenttex = c; } Fond of public zeroes (string toast) {toast. Make Text (MCTXTist, Toast, Toast. LNNGHHORT). Show (); }  

}

Angular Controller:

  Angular Module ('app'). Controller ('Complaint', Function $ Scope, $ http, Complaint Service) {$ scope.showToast = Function (Toast) {Android. Show Toast (Toast); Console.log ("toast")}}  

});

HTML:

  & lt; Button label = "Toast" ng-click = "shostost" ('Weisser Toast Forn Cooner Js') "> Toast   

Error from console :

  Reference error: is not defined on Android scope. $ Scope.showToast (http: // localhost: 3000 / script / controller Http: // localhost: 3000 / bower_components / angular-touch / Http: // localhost: 3000 / bower_components / angular / angular.js: 10567: 21 at /addcomplaint.js34:3: 438: 9 scope on / angular-touch.js. $ Eval (http: // localhost: 3000 / Bower_components / angular / angular.js: 12412: 28) Scope applies. $ (Http: // localhost: 3000 / bower_components / angular / angular.js: 12510: 23) HTMLButtonElement at HTMLButtonElement.jQuery.event.dispatch (http: //) at & lt; Anonymous & gt; (Http: // localhost: 3000 / bower_components / angular-touch / angular-touch.js: 437: 13) Localhost: 3000 / bower_components / jquery / dist / jquery js: 440 9: 9) at HTMLButtonElement.elemData.handle (http: // localhost: 3000 / bower_components / jquery / dist / jquery.js: 4095: 28)  

This is the first time I am using this kind of thing and I am not sure how to do it really. I tried to find the answer by googling but with no luck, am I doing wrong? Either change your toast functions to frozen and call it directly or instant it first.

And, you have no class named after Android , instead you have created AngularJSInterface . Change Android.showToast to AngularJSInterface.showToast (if using the static).


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -