Is there any alternative to navigator.permissions.query
Permissions API query to check geolocation
permission.
cause its still in Working Draft and has less Browser compatibility.
W3C Permissions Ref : https://www.w3.org/TR/permissions/
Issue is app resume
once user perform action on native permission popup then wanted to check the action
being taken by user.
Hybrid Cordova App callback for location permission alert
Platform : Mobile Android
NOTE : Don't want to use cordova diagnostic plugin
Example:
navigator.permissions.query({name:'geolocation'}).then(function(result) {
console.log('result : ', result);
});
The Permissions API provides the tools to allow developers to implement a better user experience as far as permissions are concerned. For example, it can query whether permission to use a particular API is granted or denied, and specifically request permission to use an API.
The Permissions API allows a web application to be aware of the status of a given permission, to know whether it is granted, denied or if the user will be asked whether the permission should be granted.
You can directly use navigator.geolocation
without asking permission first. it will automatically raise ask location prompt like the navigator.permissions
do.
navigator.geolocation.getCurrentPosition(
(i)=>console.log('success',i),
(i)=>console.log('failed',i)
)
navigator.permissions
is not supported in safari and edge, but navigator.geolocation
is supported, so i think it's safe to just execute geolocation without checking permission because it also will raise prompt permission first.
I don't think so.
At this moment the navigator.permissions object is undefined - probably it's removed in WebView by purpose to not mix web permissions with android permissions.
Option 1:
You may try Cordova diagnostic plugin, specifically the getLocationAuthorizationStatus
method which should return permission state in very similar way to Permissions API.
Please note I haven't tried the plugin.
Option 2:
Trigger location permissions dialog by requesting location.
When you'll receive PositionError with PERMISSION_DENIED
constant code, it'll mean that user denied location permission (just now or at app settings).
navigator.getCurrentPosition(
function(position) { /** won't be executed for such short timeout */ },
function(positionError) {
switch (positionError.code) {
// PERMISSION_DENIED
case 1:
console.log('Permission denied')
break
// POSITION_UNAVAILABLE
case 2:
console.log('Permission allowed, location disabled')
break
// TIMEOUT
case 3:
console.log('Permission allowed, timeout reached')
break
}
},
{timeout: 0}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With