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" > </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.