NativeScript / nativescript-camera

NativeScript plugin to empower using device camera.
Apache License 2.0
92 stars 47 forks source link

Document Android permission #140

Closed cfjedimaster closed 5 years ago

cfjedimaster commented 5 years ago

In order for this to work on Android, you must add:

<uses-permission android:name="android.permission.CAMERA"/>

While this is obvious, it really should be mentioned in the readme guide.

zbranzov commented 5 years ago

@cfjedimaster Both demo apps are working fine on Nexus 5X Android 8.1 even though they don't have this permission added. Why do you think it is a requirement? You can take permission via code:

camera.requestPermissions().then(() => {
   // you can take photos now
}).catch(() => {
   // user denied permissions
});
cfjedimaster commented 5 years ago

In my testing, when I had code that used requestPermissions, and tried to take a picture, I'd see the native prompts ("app wants to blah blah"), but the catch block would fire with: [Error: Application does not have permissions to use Camera]

This is an example of what I was trying:

camera.requestPermissions()
.then(() => {
    camera.takePicture({ width: 300, height: 300, keepAspectRatio: true, saveToGallery:true })
    .then(imageAsset => {
        this.img = imageAsset;
    })
    .catch(e => {
        console.log('error:', e);
    });
})
.catch(e => {
    console.log('Error requesting permission');
});
zbranzov commented 5 years ago

@cfjedimaster What device do you use when it fails? Did you try whether demo apps cause the same error? We are testing on android emulators and real devices using the apps from the repository and haven't seen any problem so far.

cfjedimaster commented 5 years ago

Device: Pixel 3 XL. I did not try demo apps - but I've tried it in two apps so far. The one I just tried had the same error (I mean the catch block throwing).

cfjedimaster commented 5 years ago

Device: Pixel 3 XL. I did not try demo apps - but I've tried it in two apps so far. The one I just tried had the same error (I mean the catch block throwing).

cfjedimaster commented 5 years ago

I am VERY sorry - I wrote the above comment and never hit enter.

cfjedimaster commented 5 years ago

Oops, or maybe I did in another tab - sorry for the noise.

DKhalil commented 5 years ago

@cfjedimaster hey, so there are quite a few files containing the permissions. Which file did you add it to?

tgpetrov commented 5 years ago

The usage of CAMERA permission is included in the aar file that is included in the plugin's 'platform/android' directory, so it is not necessary to include it in the application's manifest.

I created a playground with the provided code, but had no issues with the permissions when running the app. I also downloaded the playground app and was able to confirm that there is no CAMERA permission mentioned in the application's manifest file.

Can anyone reproduce the issue with the provided playground? If so, please provide the API version of the device used for testing, since there is a significant difference in the way permissions are handled since API23 (Android 6.0).