Android device camera is not opening, after allowing system permission with Ionic 3

#1

I wanted to use camera plugin in my app. I requested camera permission, but after allowing camera is not opening

Trying it on Following device

  • Moto g4 plus
    with android version 7.0

Following is Ionic info
cli packages: (C:\Users\username\AppData\Roaming\npm\node_modules)
@ionic/cli-utils : 1.19.3
ionic (Ionic CLI) : 3.20.1
global packages:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
local packages:
@ionic/app-scripts : 3.2.0
Cordova Platforms : android 7.0.0 browser 5.0.4
Ionic Framework : ionic-angular 3.9.2
System:
Android SDK Tools : 25.2.5
Node : v8.11.1
npm : 5.6.0
OS : Windows 10
Environment Variables:
ANDROID_HOME : C:\android-sdk-win
Misc:
backend : pro

Following is my code

openCamera(){

	this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.CAMERA).then(
		result => {
			alert(result.hasPermission);
			if(!result.hasPermission) {
				this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA)
				.then( cam => {
					alert('permission result '+ JSON.stringify(cam) );
					this.capturingPicture();
				})
				.catch( error => {
					alert('permission error occured '+ JSON.stringify(error) );
				});
			} else {
				this.capturingPicture();
			}
		},
		err => {
			this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA); 
		});
}

capturingPicture alert is displaying but device camera is not opening.

capturingPicture(){
	alert('capturingPicture');

	const options: CameraOptions = {
		mediaType: this.camera.MediaType.PICTURE,
		quality : 75, 
                   destinationType : this.camera.DestinationType.DATA_URL, 
                   sourceType : this.camera.PictureSourceType.CAMERA, 
                  allowEdit : true,
                  encodingType: this.camera.EncodingType.JPEG,
                  targetWidth: 300,
                  targetHeight: 300,
                 saveToPhotoAlbum: false
	};
	  
	this.camera.getPicture(options).then((imageData) => {
		let base64Image = 'data:image/jpeg;base64,' + imageData;
		alert('image data => '+ imageData);
	}, (err) => {
		// Handle error
		alert('get picture error => '+ err);
	});
}

As per documentation, wrote code, but still not getting whether it is code/plugin/verions/OS etc issue.
Please guide me with this.

thank you.

#2

Got answer…

Use following command to install camera in ionic 3
npm install --save @ionic-native/camera@4