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 • 1 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

5 year old bug, yeah

on android im stuck with: "@nativescript/camera": "^5.0.15",

{ "name": "eternalmem_ns", "version": "1.0.0", "description": "Grave fingerprints, voice, images on jewellery.", "keywords": [ "NativeScript" ], "repository": { "type": "git", "url": "https://github.com/Jaroslav84/eternalmem_ns.git" }, "author": "Yaro [email protected] (http://badcia.com/)", "license": "MIT", "homepage": "https://github.com/Jaroslav84/eternalmem_ns", "bugs": { "url": "https://github.com/Jaroslav84/eternalmem_ns.git/issues" }, "main": "./src/main.ts", "dependencies": { "@angular/animations": "~18.0.0", "@angular/common": "~18.0.0", "@angular/compiler": "~18.0.0", "@angular/core": "~18.0.0", "@angular/forms": "~18.0.0", "@angular/platform-browser": "~18.0.0", "@angular/platform-browser-dynamic": "~18.0.0", "@angular/router": "~18.0.0", "@nstudio/nativescript-floatingactionbutton": "^3.0.4", "@nativescript/angular": "^18.0.0", "@nativescript/appversion": "^2.0.0", "@nativescript/background-http": "^6.0.0", "@nativescript/camera": "^5.0.15", "@nativescript/core": "~8.8.0", "@nativescript/firebase-analytics": "^3.2.0", "@nativescript/firebase-core": "^3.2.0", "@nativescript/firebase-crashlytics": "^3.2.0", "@nativescript/imagepicker": "^2.0.1", "@nativescript/iqkeyboardmanager": "^2.1.1", "@nativescript/theme": "^3.0.0", "@nstudio/nativescript-carousel": "^8.0.3", "@nstudio/nativescript-fancyalert": "^4.0.1", "email-validator": "~2.0.4", "nativescript-audio": "^6.2.6", "nativescript-onyx-plugin": "file:../nativescript-onyx-plugin/src", "nativescript-ripple": "^4.0.3", "nativescript-ui-sidedrawer": "^15.2.3", "reflect-metadata": "~0.1.12", "rxjs": "~7.8.0", "zone.js": "~0.14.0" }, "devDependencies": { "@angular-devkit/build-angular": "~18.0.0", "@angular/cli": "~18.0.0", "@angular/compiler-cli": "~18.0.0", "@nativescript/android": "~8.8.0", "@nativescript/ios": "~8.8.0", "@nativescript/schematics": "^10.1.0", "@nativescript/types": "~8.8.0", "@nativescript/webpack": "~5.0.0", "@ngtools/webpack": "~18.0.0", "tslint": "^5.16.0", "typescript": "~5.4.0" } }

Jaroslav84 avatar Nov 12 '25 20:11 Jaroslav84