Then the completion of this is: from the index of the JS event, access to Android native activity, with android.widget.Toast display a Hello world--this time first open Extendinfo.java, modify
Private Static FinalString toast = "Toast"; @Override Public BooleanExecute (String action, Jsonarray args, Callbackcontext callbackcontext)throwsjsonexception {activity Activity= This. cordova.getactivity (); if(Action.equals ("Getextra")) {Intent I=activity.getintent (); if(I.hasextra (Intent.extra_text)) {callbackcontext.success (I.getstringextra (Intent.extra_text)); } Else{callbackcontext.error (""); } return true; }Else if(Action.equals (TOAST)) {Toast.maketext (Cordova.getactivity (),"Hello World", Toast.length_short). Show (); } return false; }}
--and then we open assets/www/plugins/com.myproj.text/www/extendinfo.js.
function var exec = require (' cordova/exec 'function(success, error) { "Extendinfo", " Getextra "function(content,type) { exec (nullnull," ExtraInfo "," Toast ", []);};});
--and then we open assets/www/cordova_plugins.js, modify the clobbers to facilitate our subsequent JS call
{ "file": "Plugins/com.myproj.test/www/extendinfo.js", "id": " Com.myproj.test.ExtraInfo ", " clobbers ": [ " Extendinfo " ] }
I understand that the extendinfo in Clobbers is the name of the call in Index.html JS.
--then we'll open the assets/www/index.html and add the JS code.
<script type= "Text/javascript" > app.initialize (); Document.addeventlistener (false); function Fun () { alert ("KK"); Extendinfo.toast (); } </script>
Our custom plugin is registered in config. s, see the last picture of the previous article. And then run you can see the page alert come out a KK Click OK, in the bottom of the interface appears toast out a Hello world Hope not understand friends can ask questions, I also check the vacancy ha.
Cordova Android Project Custom plugin and use (ii)