Dear Corona-community,
I can successfully ask for permission for using the camera on my Honor 8, running Android 7:
local hasAccessToCamera, hasCamera = media.hasSource(media.Camera) if (hasAccessToCamera == true) then --take picture media.capturePhoto( { listener=cameraListener } ) elseif(hasCamera == true and native.canShowPopup("requestAppPermission")) then -- A camera exists, but there is no access to it! native.showPopup( "requestAppPermission", { appPermission="Camera" } ) else [...]
Problem is that if I try to add an image from the photolibrary BEFORE getting this permission, media.selectPhoto does not work. So, I guess media.selectPhoto also requires this permission.
According to
https://docs.coronalabs.com/api/library/media/hasSource.html
only media.hasSource( media.Camera ) returns two booleans. But it looks like there is nothing similar for media.hasSource(media.PhotoLibrary).
I tried to ask for the same permission when trying to add an image from library:
local hasAccessToGallery, hasGallery = media.hasSource(media.Camera) if (hasAccessToGalery == true) then -- get picture from gallery media.selectPhoto( { mediaSource = media.photoLibrary, listener = cameraListener } ) elseif(hasGallery == true and native.canShowPopup("requestAppPermission")) then -- gallery exists, but there is no access to it! native.showPopup( "requestAppPermission", { appPermission="Camera" } ) else [...]
which results in asking for permission when I click on my gallery-button. Problem is, even if I accept permission, next time I click on the button corona crashes again, giving me a nil for event.target in my listener.
Any ideas?
