NativeScript / nativescript-camera

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

Camera does not offer tick nor cross to accept photo after accepting permissions and taking photo #161

Open Sam-Davis opened 5 years ago

Sam-Davis commented 5 years ago

Which platform(s) does your issue occur on?

Android

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it.

The first time the camera is loaded on an emulator, the user is asked for permissions. The standard permissions to access the device camera are requested, but unexpectedly the user is also asked if they want the device to have access to their location.

Whether or not the user agrees to allow the app to have access to their location, the next screen is the take photo screen (as expected). However, when the user clicks on the camera icon to take a photo, they are not shown the tick or cross asking them if they want to keep the photo. Instead the camera button displays and they can continue taking photos indefinitely.

If the user presses the back button and goes into this screen again, then the user is redirected to the page with the tick and the cross as expected.

I'm guess that this is caused by a race condition, where the take photo starts before all the permissions are approved.

The code to take the photo appears to be waiting for the permissions to have been granted:

 camera.requestPermissions().then(
     function success() {
         var options = { width: 300, keepAspectRatio: true, saveToGallery: true };
         var takePictrue = camera.takePicture(options);
         takePictrue.then((imageAsset: ImageAsset) => {
...

I have asked this question on stack overflow: https://stackoverflow.com/questions/54197418/nativescript-camera-doesnt-show-tick-nor-cross-after-taking-a-photo

stevenspiel commented 5 years ago

I'm also experiencing this

DimitarTodorov commented 5 years ago

Hi @Sam-Davis

I can confirm that there is indeed an issue with camera-plugin. We are going to put the bug in our plan and will provide a fix for it. You can follow this thread for further information, I'll post here once a fix is available.

Sam-Davis commented 5 years ago

We have tried to implement a workaround for this bug, but it appears that this bug is a blocker. We implemented the permissions check in a previous page:

camera.requestPermissions().then(
     function success() {

which we hoped would mean that the following does not ask for permissions:

 camera.requestPermissions().then(
     function success() {
         var options = { width: 300, keepAspectRatio: true, saveToGallery: true };
         var takePictrue = camera.takePicture(options);
         takePictrue.then((imageAsset: ImageAsset) => {

However, it just means that it only asks for the location. The permissions check ( camera.requestPermissions().then will ask two questions relating to the cemeras permissions, but it does not ask for location. Then takePictrue.then will result in permissions being asked. At this point it is too late for permissions to be requested.

I'm not sure why .takePicture is requsting the user's location. You shouldn't need to tell an app your location to take a picture.

Sam-Davis commented 5 years ago

On further investigation, this bug has a lesser impact than previously thought.

It breaks when you open the camera on a device for the first time and it says:

"Allow camera to access this device's location?" (photo location question)

It then redirects the user back to the camera app after allowing permission, rather than back to the nativescript app.

If the user first opens the camera app on the phone and responds to this photo location question and then opens the nativescript app, then the error does not occur. Therefore, this error should effect a very small proportion of users.

tgpetrov commented 5 years ago

Hi @Sam-Davis, I can confirm your observations.

On android the camera plugin is using an Image Capture intent to take an image through a camera app installed on the device. The expected behavior is that the user doesn't leave the app while doing the image picking. However it seems that since API24, the default android camera app starts automatically if it has never been started when the plugin requests this intent.

I haven't found a way to improve the plugin in this particular scenario, but if someone has more information and ideas, PRs are welcome.