问题
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);
});
回答1:
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}
)
来源:https://stackoverflow.com/questions/52784495/is-there-any-alternative-to-navigator-permissions-query-permissions-api