Cordova Android Project Custom plugin and use (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.