I am working on BLE Bluetooth scanning is working on all devices except the Android 10 & 11. After updating the application, Bluetooth scanning in Android 10 & 11 are not working. Sometimes even after the location permission is allowed, the application has to re-grant permission from the application settings. Why is this not being known while always getting true in the
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){ //Code here.. }
Please verify that you have implemented the location permission check according to the os version
Android 8 (≥8): background apps can only retrieve a user’s location a few times each hour.
Before Android 10(<10), location permission was a single resource: apps only required permission once to use everywhere (foreground and background) and every time.
Android 10(≥10), background location came as an independent resource. Apps have to request explicitly this permission besides the foreground one.
Android 11(≥11), background location permission can’t be requested at the same time as others. Apps have to request it separately. Moreover, requesting this permission doesn’t prompt the user immediately as for the other permissions but it will take the user to the /Settings page/Location permission session so that the user can update the level of permission.
Note : sometimes when the application is installed in work mode profile we have to manually enable the permission from setting even we are allowing it from the application
Try to actually request the permission from the user on start of your app using requestPermissions:
// Request location permission, needed for BLE Scan
ActivityCompat.requestPermissions(this,
new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION},
2);
You can find more information on how to handle this event better on this page of the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With