nativescript-camera icon indicating copy to clipboard operation
nativescript-camera copied to clipboard

cameraFacing: "front" does not work in Android

Open fvtrx opened this issue 5 years ago • 0 comments

Hi, just want to ask if there is any chance that I can force my cameraFacing to display front camera in Android? I tried to follow the exact methods in the documentation but still doesn't return the front camera that I wanted in Android devices.

Is there any workaround for this? I've attached the details of my issues below.

Which platform(s) does your issue occur on?

  • Android

Please, provide the following version numbers that your issue occurs with:

  • CLI: 6.7.4
  • Cross-platform modules: 6.4.1
  • Runtime(s): Android: 6.4.1
  • Plugin(s): "nativescript-camera": "^4.5.0",

Is there any code involved?

Sample code is shown as below:

    requestPermissions().then(() => {
         let cameraProps = {};
         if (isAndroid) {
           cameraProps = {
             width: 250,
             height: 250,
             keepAspectRatio: true,
             saveToGallery: false,
             cameraFacing: "front",
           };
         } else {
           cameraProps = {
             width: 250,
             height: 250,
             keepAspectRatio: true,
             saveToGallery: false,
             cameraFacing: "front",
           };
         }
         takePicture(cameraProps).then(
           (imageAsset) => {
             if (isAndroid) {
               that.photoItems.push({
                 filename: imageAsset._android.replace(/^.*[\\\/]/, ""),
                 file: imageAsset._android,
               });
             } else {
               let currentDate = Date.now();
               let source = new imageSourceModule.ImageSource();
               source.fromAsset(imageAsset).then((source) => {
                 let folder = fs.knownFolders.documents();
                 let path = fs.path.join(
                   folder.path,
                   "image_" +
                     (that.photoItems.length + 1) +
                     "_" +
                     currentDate +
                     ".jpg"
                 );
                 let saved = source.saveToFile(path, "jpg", 10);
                 that.photoItems.push({
                   filename:
                     "image_" +
                     (that.photoItems.length + 1) +
                     "_" +
                     currentDate +
                     ".jpg",
                   file: path,
                 });
               });
             }
           },
           (err) => {
             console.info(err);
           }
         );
       },
       () => alert("permissions rejected")
    );

fvtrx avatar Oct 07 '20 02:10 fvtrx