javascript - Calling an Android function from AngularJS controller -
i have problem need help with. i'm trying phone call android function using angular controller in frontend, can't work.
mainactivity:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mwebview = (webview)findviewbyid(r.id.activity_main_webview); mwebview.setwebviewclient(new customwebviewclient()); websettings websettings = mwebview.getsettings(); websettings.setjavascriptenabled(true); mwebview.addjavascriptinterface(new angularjsinterface(this), "android"); mwebview.loadurl("http://192.168.70.101:3000/"); }
angularjsinterface:
public class angularjsinterface { context mcontext; angularjsinterface(context c) { mcontext = c; } public void showtoast(string toast) { toast.maketext(mcontext, toast, toast.length_short).show(); }
}
angular controller:
angular.module('app').controller('complaintctrl', function ($scope, $http, complaintservice) { $scope.showtoast = function(toast) { android.showtoast(toast); console.log("toast"); }
});
the html:
<button label="toast" ng-click="showtoast('visar toast från angularjs')">toast</button>
error console:
referenceerror: android not defined @ scope.$scope.showtoast (http://localhost:3000/scripts/controllers/addcomplaint.js:34:3) @ http://localhost:3000/bower_components/angular/angular.js:10567:21 @ http://localhost:3000/bower_components/angular-touch/angular-touch.js:438:9 @ scope.$eval (http://localhost:3000/bower_components/angular/angular.js:12412:28) @ scope.$apply (http://localhost:3000/bower_components/angular/angular.js:12510:23) @ htmlbuttonelement.<anonymous> (http://localhost:3000/bower_components/angular-touch/angular-touch.js:437:13) @ htmlbuttonelement.jquery.event.dispatch (http://localhost:3000/bower_components/jquery/dist/jquery.js:4409:9) @ htmlbuttonelement.elemdata.handle (http://localhost:3000/bower_components/jquery/dist/jquery.js:4095:28)
this first time i'm using sort of thing , i'm not quite sure how it. i've tried looking answers googling no luck. doing wrong?
either alter toast function static , phone call straight or instantiate first. and, have no class named android
instead have created angularjsinterface
. alter android.showtoast
angularjsinterface.showtoast
(if using static).
javascript android angularjs webview
No comments:
Post a Comment