Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BLE Bluetooth scanning is not working on Android 10 & 11 due to location permission

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.. }

like image 995
Amulya Maheshwari Avatar asked Sep 03 '25 01:09

Amulya Maheshwari


2 Answers

Please verify that you have implemented the location permission check according to the os version

  1. Android 8 (≥8): background apps can only retrieve a user’s location a few times each hour.

  2. Before Android 10(<10), location permission was a single resource: apps only required permission once to use everywhere (foreground and background) and every time.

  3. Android 10(≥10), background location came as an independent resource. Apps have to request explicitly this permission besides the foreground one.

  4. 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

like image 178
Radhika bajaj Avatar answered Sep 10 '25 23:09

Radhika bajaj


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.

like image 21
Michael Kotzjan Avatar answered Sep 10 '25 23:09

Michael Kotzjan