Location permission android 12
jackyhieu1211-hn opened this issue · comments
Location permission android 12
-- Hello admin.
I checking android 12 and have a problem:
In android 12. App must request both permission ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION
My code:
@NeedsPermission(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
fun getLocation() {
// Code here
}
@OnPermissionDenied(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
fun getLocationDenied() {
// Code here
}
When I choose option Approximate -> While using the app
Actual results: OnPermissionDenied called.
Expected results : getLocation() will call
=> Reason: method verifyPermissions in class PermissionUtils checking.
- Checks all given permissions have been granted.
- Params:
- grantResults – results
- Returns:
- returns true if all permissions have been granted.
Please help me.
@hotchemi Please check.thank you very much
Thx for the report, we should address this issue before Android 12. Just in case which module are you using right now?
I made a temporary fix as follows
@OnPermissionDenied(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
fun getLocationDenied() {
checkAccessCoarseLocation()
}
@OnNeverAskAgain(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
fun onNeverAskLocationAgain() {
checkAccessCoarseLocation()
}
private fun checkAccessCoarseLocation() {
if (context?.isAccessCoarseLocationGranted() == true) {
getLocation()
} else {
Log.e("Error", "Permission")
}
}
fun Context.isAccessCoarseLocationGranted(): Boolean {
if (isAndroidS().not()) return false
return PermissionUtils.hasSelfPermissions(this, Manifest.permission.ACCESS_COARSE_LOCATION)
}
fun isAndroidS(): Boolean {
return Build.VERSION.SDK_INT >= 31
}