Skip to content

cameraFacing: "front" does not work in Android #254

Open
@fvtrx

Description

@fvtrx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions