Skip to content

Commit 62bd1d5

Browse files
committed
Fix: await Permission.location.request() returns PermissionStatus.denied when user selects approximate
1 parent d842345 commit 62bd1d5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,25 @@ public boolean onRequestPermissionsResult(
247247
PermissionUtils.toPermissionStatus(this.activity, permissionName, result);
248248

249249
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
250-
if (!requestResults.containsKey(PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS)) {
250+
if (!requestResults.containsKey(PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS) ||
251+
requestResults.get(PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS) != PermissionConstants.PERMISSION_STATUS_GRANTED) {
251252
requestResults.put(
252253
PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS,
253254
permissionStatus);
254255
}
255256
}
256257

257-
if (!requestResults.containsKey(PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE)) {
258+
if (!requestResults.containsKey(PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE) ||
259+
requestResults.get(PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE) != PermissionConstants.PERMISSION_STATUS_GRANTED) {
258260
requestResults.put(
259261
PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE,
260262
permissionStatus);
261263
}
262264

263-
requestResults.put(permission, permissionStatus);
265+
if (!requestResults.containsKey(permission) ||
266+
requestResults.get(permission) != PermissionConstants.PERMISSION_STATUS_GRANTED) {
267+
requestResults.put(permission, permissionStatus);
268+
}
264269
// [grantResults] can only contain PermissionConstants.PERMISSION_STATUS_GRANTED or PermissionConstants.PERMISSION_STATUS_DENIED status.
265270
// But these permissions can have status PermissionConstants.PERMISSION_STATUS_LIMITED, so we need to recheck status
266271
} else if (permission == PermissionConstants.PERMISSION_GROUP_PHOTOS || permission == PermissionConstants.PERMISSION_GROUP_VIDEOS) {
@@ -502,6 +507,19 @@ private int determinePermissionStatus(final @PermissionConstants.PermissionGroup
502507
: PermissionConstants.PERMISSION_STATUS_DENIED;
503508
}
504509

510+
if (context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.M) {
511+
if (permission == PermissionConstants.PERMISSION_GROUP_LOCATION ||
512+
permission == PermissionConstants.PERMISSION_GROUP_LOCATION_ALWAYS ||
513+
permission == PermissionConstants.PERMISSION_GROUP_LOCATION_WHEN_IN_USE) {
514+
boolean isCoarseGranted = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
515+
boolean isFineGranted = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
516+
517+
if (isCoarseGranted || isFineGranted) {
518+
return PermissionConstants.PERMISSION_STATUS_GRANTED;
519+
}
520+
}
521+
}
522+
505523
final boolean requiresExplicitPermission = context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.M;
506524

507525
if (requiresExplicitPermission) {

0 commit comments

Comments
 (0)