Skip to content

Commit

Permalink
[Android] Fix location permission check below Android 12 (#23567)
Browse files Browse the repository at this point in the history
  • Loading branch information
panliming-tuya authored and pull[bot] committed Sep 15, 2023
1 parent abfbdbb commit 2334288
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,21 @@ class SelectActionFragment : Fragment() {
}

private fun hasLocationPermission(): Boolean {
val locationPermissionState =
ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION)
var blePermissionState = 1
val locationPermissionGranted =
ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED

// Android 12 new permission
var bleScanPermissionGranted = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
blePermissionState =
ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.BLUETOOTH_SCAN)
bleScanPermissionGranted =
ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.BLUETOOTH_SCAN) ==
PackageManager.PERMISSION_GRANTED
}

return PackageManager.PERMISSION_GRANTED == (locationPermissionState + blePermissionState)
return locationPermissionGranted && bleScanPermissionGranted
}


Expand Down

0 comments on commit 2334288

Please sign in to comment.