android – ionic front camera does not open-ThrowExceptions

Exception or error:

Using ionic plugin “name”: “cordova-plugin-camera”,”version”: “2.2.0”. I am not getting front facing camera but opens back facing camera, also tried with cameraDirection : 1 as described on the link but it results in back facing camera. i have tested on Android 4.4 and 5.1
is there any way to get front facing camera open by switching or any other way or any fix?

Also debugged straight inside camera plugin code as on the link here i also got cameraDirection = 1 which is for front facing camera, but unable to resolve the problem.

$ionicPlatform.ready(function() {
  //camera settings
  $rootScope.options = {
    quality: 50,
    destinationType: Camera.DestinationType.DATA_URL,
    sourceType: Camera.PictureSourceType.CAMERA,
    encodingType: Camera.EncodingType.JPEG,
    targetWidth: 100,
    targetHeight: 100,
    popoverOptions: CameraPopoverOptions,
    saveToPhotoAlbum: false,
    correctOrientation:true,
    cameraDirection : Camera.Direction.FRONT
  };
  $cordovaCamera.getPicture($rootScope.options).then(function cameraSuccess(imageData) {
    $rootScope.imageData = imageData;
  },function cameraError(err){
    console.log(err);
    $rootScope.imageData = '';
  })
})
How to solve:

According to Docs you have to pass number in cameraDirection

So in your code write as follow:

 $rootScope.options = {
   quality: 50,
   destinationType: Camera.DestinationType.DATA_URL,
   sourceType: Camera.PictureSourceType.CAMERA,
   encodingType: Camera.EncodingType.JPEG,
   targetWidth: 100,
   targetHeight: 100,
   popoverOptions: CameraPopoverOptions,
   saveToPhotoAlbum: false,
   correctOrientation:true,
   cameraDirection : 1 // 0 means BACK, 1 means FRONT
 };

Leave a Reply

Your email address will not be published. Required fields are marked *