I'm calling the function below:
this.androidPermissions.requestPermission("ACCESS_FINE_LOCATION")
.then((data: any) {
if(data.hasPermission) {
console.log("have permission");
}
});
But I do not get the permission popup. I have tried with the catch block, but I don't see any error.
Update 1: I have tried this answer, but I am still not getting the permissions popups. https://stackoverflow.com/a/47650104/758373
So I think this could be caused by two things.
The first being: How you are utilizing the permission in your code.
Android 26 and above: due to Android 26's changes to permissions handling (permissions are requested at time of use rather than at runtime,) if your app does not include any functions (eg. other Ionic Native plugins) that utilize a particular permission, then requestPermission() and requestPermissions() will resolve immediately with no prompt shown to the user. Thus, you must include a function utilizing the feature you would like to use before requesting permission for it.
From my understanding, this wouldn't be caught in your catch
statement, because nothing is being caught, there was no error perse. It might be caught in your then
statement though, but it is also likely that it isn't. Try writing a statement to see if data: any
is null. Some plugins send a callback when they are canceled, and some don't. It's all up to the developer's desrection.
Also, I believe that you are asking for the permission incorrectly.
Change this
this.androidPermissions.requestPermission("ACCESS_FINE_LOCATION")
.then((data: any) {
if(data.hasPermission) {
console.log("have permission");
}
});
To this:
this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.ACCESS_FINE_LOCATION).then((data:any) => {
if(data.hasPermission) {
console.log("have permission");
}
});