Camera permissions are ignored?


#1

Currently my AndroidManifest.xml is :

    ...
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    ...

Now - When I’m using :

   camera.takePicture({
                width:           400,
                height:          400,
                keepAspectRatio: true,
                saveToGallery:   false
            })

I get an error :

JS: Error -> Application does not have permissions to use Camera

But If I prepend this code :

  camera.requestPermissions();

Then I see the permission dialog and when approved , it does uses the camera

Question

I explicitly declared camera permission in the manifest.
So why is it ignored ? What should I change in order for the permission in manifest to be respected ?
Showing the user a permission dialog each time - is very nonprofessional.


#2

@Royi_Namir to use the camera on Android versions 5 and up (API 21+), you need to explicitly request permissions at runtime - which is why manifest declarations alone are not enough.

Now, I am not aware which camera plugin you are using, but you could use nativescript-permissions to check whether a permission is granted, and on consecutive calls only check the cached result, so you don’t have to ask the user each time.