🥳 NativeScript 6.0 is here! Learn all about it at our launch webinar.

NativeScript Angular

Camera

NativeScript plugin to empower using device camera.

Install the camera plugin as dependency

npm i nativescript-camera --save

Note: On Android 6.0 and above it is neccessary to request permissions for camera (to be able to take picture) and access for Photos (to be able to share the image via Google Photos app). NativeScript-camera plug-in has a dedicated method called requestPermissions() which can be used in that case.

Using Camera

Initializing camera

Taking photo with provided options width, height, keepAspectRatio and saveToGallery

public imageTaken: ImageAsset;
public saveToGallery: boolean = true;
public keepAspectRatio: boolean = true;
public width: number = 300;
public height: number = 300;

onTakePhoto() {
    let options = {
        width: this.width,
        height: this.height,
        keepAspectRatio: this.keepAspectRatio,
        saveToGallery: this.saveToGallery
    };

    takePicture(options)
        .then(imageAsset => {
            this.imageTaken = imageAsset;
            console.log("Size: " + imageAsset.options.width + "x" + imageAsset.options.height);
        }).catch(err => {
            console.log(err.message);
        });
}

Requesting permissions

onRequestPermissions() {
    requestPermissions();
}

Checking if camera hardware is available

onCheckForCamera() {
    let isCameraAvailable = isAvailable();
    console.log("Is camera hardware available: " + isCameraAvailable);
}

Improve this document

Demo Source