NativeScript / nativescript-camera

NativeScript plugin to empower using device camera.
Apache License 2.0
92 stars 47 forks source link

Nativescript Camera Front Facing (Android) #253

Closed fvtrx closed 3 years ago

fvtrx commented 3 years ago

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?

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

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")
     );