Skip to content

nativescript/camera not working on Android phones #252

@Adamok258

Description

@Adamok258

Hi, we experience problems with our Android application that uses nativescript camera (this does not affect iOS). We don't have detailed info but this wasn't happening before, it has started just couple of days/weeks before and it seems to affect almost all Android versions, we could replicate it on 9, 10, 11 and 12. Basically when user tries to open camera app it crashes and displays error message to user before opening.

We are using nativescript/camera 5.0.10.

"dependencies": {
    "@angular/animations": "^12.2.5",
    "@angular/common": "^12.2.5",
    "@angular/compiler": "^12.2.5",
    "@angular/core": "^12.2.5",
    "@angular/forms": "^12.2.5",
    "@angular/platform-browser": "^12.2.5",
    "@angular/platform-browser-dynamic": "^12.2.5",
    "@angular/router": "^12.2.5",
    "@nativescript/angular": "^12.2.0",
    "@nativescript/background-http": "^5.0.1",
    "@nativescript/camera": "^5.0.10",
    "@nativescript/core": "^8.1.5",
    "@nativescript/geolocation": "^7.1.1",
    "@nativescript/local-notifications": "^5.1.0",
    "@nativescript/theme": "~3.0.0",
    "@ngx-translate/core": "^13.0.0",
    "@nstudio/nativescript-loading-indicator": "^4.1.2",
    "moment": "^2.29.1",
    "nativescript-clipboard": "^2.0.0",
    "nativescript-permissions": "^1.3.12",
    "reflect-metadata": "~0.1.12",
    "rxjs": "~7.3.0",
    "zone.js": "~0.11.1"
  },

This is the code that takes care of asking for permission and taking the picture, which crashes on Android and displays the error message in the bottom part of the code:

this.cameraService.requestPermissions()
            .pipe(
                tap(() => {
                    timeModule.setTimeout(() => {
                        this.takingPhoto = true;
                        this.onPhotoInProgressChanged.emit(true);
                    }, 1000);
                }),
                flatMap(() => this.cameraService.takePhoto(this.stepName)),
                tap(() => {
                    this.takingPhoto = false;
                })
            )
            .subscribe((photoWithThumbnail: PhotoWithThumbnail) => {
                this.takenPhoto = photoWithThumbnail;
                if (this.stepItemTypes) {
                    if (this.chosenItemType) {
                        this.onPhotoInProgressChanged.emit(false);
                        this.onPhotoTaken.emit(photoWithThumbnail);
                    }
                } else {
                    this.onPhotoInProgressChanged.emit(false);
                    this.onPhotoTaken.emit(photoWithThumbnail);
                }
            }, error => {
                this.takingPhoto = false;
                this.onPhotoInProgressChanged.emit(false);
                if (error.message === 'cancelled') {
                    return;
                }
                if (error.message === 'widePhotoTaken') {
                    this.handleWidePhotoTakenError();
                    return;
                }
                this.errorHandlingService.handle('Error taking photo', error, 'selfInspection.error.camera', true);
            });

Thank you in advance for any help/recommendation.

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