media.hasSource(media.Camera) always returns true on Android 6.0 Marshmallow

We’re having a problem because media.hasSource(media.Camera) always returns true on Android 6.0 Marshmallow, even if the user has specifically turned off that permission in their settings.

We just started using the QR Code Scanner plugin, and it crashes tremendously because of this. We can’t prevent it because the code that we’re supposed to use to determine if we have permission is returning true all the time.

Any help would be greatly appreciated.

Thanks,

Dave

Actually, the problem seems more widespread.  I have the same issue with this check on iOS 9.1 as well, on my iPhone 6.

I simply go turn off the Camera permission specifically for my app, then run it, and it bypasses my check.

 -- show the native camera if (media.hasSource(media.Camera)) then ... media.capturePhoto({ listener = utils.genericListenerWithParameter(onPhotoComplete,{fromGallery = false}), destination = {baseDir=system.TemporaryDirectory, filename=displayFilename, type="image"} }) else native.showAlert("Error", "Cannot access the camera on this device.", { "OK" }) end

^ This code will open the camera anyway, even though the permission is turned off. The camera won’t be able to take a picture, though, and the screen will be black. Still, it should have given us the error message instead.

Dave

Hi dave.haynes,

Speaking on the Android side, this is technically the correct behavior, since Corona apps target Android 5.0. Because of this, when you try to alter the permissions to a Corona app, you should see a warning pop up saying something along the lines of “This app was designed to have all permissions granted. Turning one off may make the app unstable”.

All that being said, until we provide official Android 6.0 support for Corona SDK, altering permissions shouldn’t even be part of your testing since it violates how the app was designed. For Enterpise users that have changed the targetSdkVersion to 23 in the AndroidManifest.xml, I’d say this is an issue, since the Corona app now works against its intended design.

We’ll investigate this further in the case of Enterprise users for now. Support for handling runtime permission has been one of the biggest pieces of work for us to get official Android 6 support for Corona SDK, but things are looking positive thus far.

What about iOS though? Are you guys seeing the same issue there? I am, and another developer on my team is also seeing that media.hasSource(media.Camera) seems to return true all the time regardless of the permission setting…

On iOS, we do see the same issue.

Technically, the API is doing what it’s advertised to do on iOS, but obviously we don’t provide a way for checking if you have permission to use that resource, making this advertised behavior practically useless in this case.

We’ll change the API to respect app permission settings and will continue investigating areas where app permission settings may not be respected.

Hi dave.haynes,

This issue has been resolved on iOS as of daily build 2015.2744. When using media.hasSource() the API will return false if the user has denied the app access to the Camera or Photos library.

Actually, the problem seems more widespread.  I have the same issue with this check on iOS 9.1 as well, on my iPhone 6.

I simply go turn off the Camera permission specifically for my app, then run it, and it bypasses my check.

 -- show the native camera if (media.hasSource(media.Camera)) then ... media.capturePhoto({ listener = utils.genericListenerWithParameter(onPhotoComplete,{fromGallery = false}), destination = {baseDir=system.TemporaryDirectory, filename=displayFilename, type="image"} }) else native.showAlert("Error", "Cannot access the camera on this device.", { "OK" }) end

^ This code will open the camera anyway, even though the permission is turned off. The camera won’t be able to take a picture, though, and the screen will be black. Still, it should have given us the error message instead.

Dave

Hi dave.haynes,

Speaking on the Android side, this is technically the correct behavior, since Corona apps target Android 5.0. Because of this, when you try to alter the permissions to a Corona app, you should see a warning pop up saying something along the lines of “This app was designed to have all permissions granted. Turning one off may make the app unstable”.

All that being said, until we provide official Android 6.0 support for Corona SDK, altering permissions shouldn’t even be part of your testing since it violates how the app was designed. For Enterpise users that have changed the targetSdkVersion to 23 in the AndroidManifest.xml, I’d say this is an issue, since the Corona app now works against its intended design.

We’ll investigate this further in the case of Enterprise users for now. Support for handling runtime permission has been one of the biggest pieces of work for us to get official Android 6 support for Corona SDK, but things are looking positive thus far.

What about iOS though? Are you guys seeing the same issue there? I am, and another developer on my team is also seeing that media.hasSource(media.Camera) seems to return true all the time regardless of the permission setting…

On iOS, we do see the same issue.

Technically, the API is doing what it’s advertised to do on iOS, but obviously we don’t provide a way for checking if you have permission to use that resource, making this advertised behavior practically useless in this case.

We’ll change the API to respect app permission settings and will continue investigating areas where app permission settings may not be respected.

Hi dave.haynes,

This issue has been resolved on iOS as of daily build 2015.2744. When using media.hasSource() the API will return false if the user has denied the app access to the Camera or Photos library.