Any assistance rendered here is well appreciated. Thanks for your contribution in advance.
Please my problem is that I integrated cordova-plugin-camera and I have a read lot of its documentation but I still find it difficult to implement.
Please what I want is that when I click a button camera should be opened for camera usage or where to select image.
I have read this documentation several time and I understand but attaching button click event to do this is my problem.
These are the sample code I got from the documentation:
function openCamera(selection) {
var srcType = Camera.PictureSourceType.CAMERA;
var options = setOptions(srcType);
var func = createNewFileEntry;
if (selection == "camera-thmb") {
options.targetHeight = 100;
options.targetWidth = 100;
}
navigator.camera.getPicture(function cameraSuccess(imageUri) {
displayImage(imageUri);
// You may choose to copy the picture, save it somewhere, or upload.
func(imageUri);
}, function cameraError(error) {
console.debug("Unable to obtain picture: " + error, "app");
}, options);
}
function setOptions(srcType) {
var options = {
// Some common settings are 20, 50, and 100
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
// In this app, dynamically set the picture source, Camera or photo gallery
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true,
correctOrientation: true //Corrects Android orientation quirks
}
return options;
}
function displayImage(imgUri) {
var elem = document.getElementById(‘imageFile’);
elem.src = imgUri;
}
What the documentation suggested is this
cordova-plugin-camera
This plugin defines a global navigator.camera
object, which provides an API for taking pictures and for choosing images from the system’s image library.
Although the object is attached to the global scoped navigator
, it is not available until after the deviceready
event.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(navigator.camera);
}
Please where do I add this addEventListener and where do I use the above code on deviceReady.
Please I know this is not related to framework7 issues but I know many here might have solved this issue before.
I am using core framework7 v5, componentUrl. From this page called upload/snap picture for upload I would like to have a button that when user click it, it will trigger openCamera and send the result to the server.
Thanks for your response in advance.