Cordova Learning notes the use of _cordova plug-ins (camera) __cordova

Source: Internet
Author: User

A brief introduction to the creation of the project is now to see how the Cordova plug-ins are used. Adding Cordova Plug-ins can invoke some features or controls that are native to the phone.
First add the camera plugin:

Cordova Plugin Add Cordova-plugin-camera

How to use it specifically.

<div class= "App" > <div class= "divupload" > <input type= "button" value= "Select Picture" class= "AddButton" I d= "btnaddimg"/> <div id= "showimg" class= "Imgshowdiv" align= "center" > <img id= "imgshow" src = "Img/upload_img.png" class= "Imgshow"/> </div> <input type= "button" value= "Upload picture" class= "addbut Ton "id=" btnuploadimg "/> </div> <div id=" Divchoosepic "class=" divchoosepic "> <input t Ype= "button" value= "Photo" class= "Choosebutton" id= "Btnchoosefromcamera" > <input "button" Type= "album" Class = "Choosebutton" id= "btnchoosefromlocal" > <input type= "button" value= "Cancel" class= "Choosebutton" id= "BTNCANCELC Hoose "> </div> </div> </body> <script type=" Text/javascript "src=" Cordova.js "></script
    > <script> var divchoosepic = Initview ("Divchoosepic");
    var imgshow = Initview ("Imgshow"); Add a contact person Clicklistener ("btnaddimg", Showchoosediv);
    Clicklistener ("Btnchoosefromcamera", calltakepicture);
    Clicklistener ("Btnchoosefromlocal", addlocalpicture);

    Clicklistener ("Btncancelchoose", cancelchoosepic);
        Photo function Calltakepicture () {showchoosediv (2); Navigator.camera.getPicture (onsuccess, Onfail, {quality:50, DestinationType:Camera.DestinationT Ype.

        Data_url}); function onsuccess (imagedata) {//Place the selected control on the control to be displayed imgshow.src = "data:image/jpeg;base64," + imaged
        Ata

        };
        function Onfail (message) {alert (' Failed because: ' + message);


    };

    };

        Select Local picture function Addlocalpicture () {showchoosediv (1); Navigator.camera.getPicture (onsuccess, Onfail, {quality:50, DestinationType:Camera.DestinationT Ype.

        Data_url, SourceType:Camera.PictureSourceType.PHOTOLIBRARY});
 function onsuccess (ImageURL) {           Place the selected control on the control you want to display IMGSHOW.SRC = "data:image/jpeg;base64," + ImageURL;

        };
        function Onfail (message) {Navigator.notification.alert (' Failed because: ' +message, ' action hint ', ' OK ');

    };


    };
        function Cancelchoosepic () {alert ("Cancel");
    Showchoosediv (1);

    }; Picture selection box shows hidden function showchoosediv (flag) {if (flag = 1) {//Hide DivChoosePic.style.display = "Non
            E ";
        Return
            } if (flag = = 2) {//Display DivChoosePic.style.display = "block";
    return} DivChoosePic.style.display = "block";
};
 </script>

above.

Related Article

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.

Tags Index: