I recently updated my Ionic project to support Android 14. However, after the update, I’m encountering an issue where the camera plugin (cordova-plugin-camera) only opens after several clicks on the button. Before the update, the camera would open immediately after a single click.
` takePicture(record){
console.log(‘takePicture:’+record);
const popoverOptions: CameraPopoverOptions = {
x: 250,
y: 430,
width: 100,
height: 200,
arrowDir: this.camera.PopoverArrowDirection.ARROW_LEFT
};
const options: CameraOptions = {
quality: 50,
targetWidth: 1024,
targetHeight: 1024,
encodingType: this.camera.EncodingType.JPEG,
//sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
sourceType: record ? this.camera.PictureSourceType.CAMERA : this.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: this.camera.DestinationType.FILE_URI, //FILE_URI not working on ios (Cordova Camera iOS Issue: NOT_FOUND_ERR)
popoverOptions: popoverOptions,
correctOrientation: true
}
this.camera.getPicture(options).then((image) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
//this.videoUrl = videoUri;
//console.log('image:'+image);
//this.imageUrl = 'data:image/jpeg;base64,'+image;
console.log('takenPicture:'+image);
console.log('Image:'+image);
this.selectedImageUri = image;
if(this.selectedImageUri.indexOf('?')>0){
this.selectedImageUri = this.selectedImageUri.substring(0, this.selectedImageUri.indexOf('?'));
}
this.loadFile(this.selectedImageUri);
}, (err) => {
// Handle error
});
}`
Steps I’ve Taken:
Updated all the necessary plugins to ensure compatibility with Android 14.
Verified that the cordova-plugin-camera is the latest version.
Checked permissions and ensured that the app has camera access.
Tested on multiple devices. This issue only in Android 14 devices.
Issue:
After clicking the button that triggers the getPicture method, the camera only opens after several clicks instead of immediately.
sarath t is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.