1

I am using Samsung Note 8 (Android 9) and Samsung A50(Android 10).

I am doing BLE scan which needs Bluetooth as well as location permissions (Android >=23). I am NOT providing the Location permission to the App before starting the BLE scan.

While starting a scan on Note 8, I am getting onScanFailed() callback with error code 2 (SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) when the location permission is not given.

While starting scan on A50, I do not get any callbacks. From the adb logs I can see internal log like BluetoothUtils: Permission denial: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATIONpermission to get scan results 07-28 21:03:35.720 2010 2650 D

I want to identify a scan failure has occurred because of missing permission. How do i do that?

Note- I am building an Android library, not an Android App so please suggest accordingly.

1 Answers1

1

There are a few things it could be. Firstly note for a BLE scan you need permission to location and bluetooth. Therefore, in your developing environment you will need to specify this. For example in android studio you need to go into the manifest and specifically give permission to both bluetooth and location. See below:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

However, this will not be enough as within your phone app you will need to give the permission from the user.

As you are running android you will need to give the location permission(and turn on location and bluetooth) then the scan will work.

To allow location go to:

  • Settings
  • Your apps
  • Find your app
  • App info
  • Permissions
  • Allow location permission

To summarise check your IDE has the permissions enabled. Then check on the app(on the phone) that the user has allowed the permission.

Thomas Morris
  • 794
  • 5
  • 26
  • I have already added these required permissions to the AndroidManifest. Also i can enable the permission from the settings but what if a user doesnot enable (or revokes) the permission, then i want to identify that in the API call. Any inputs on that? Thanks for responding. – Sameeksha Jain Jul 31 '20 at 11:02
  • Then you want a catch statement when you run the scan when you try to run the scan without permission. I would just toast to the user need to enable the permission. Or better create a popup for the permission. – Thomas Morris Jul 31 '20 at 11:30
  • Yeah but scan failure can be due to different reasons, so i would not like to show a pop up everytime for missing permission to the user, how do i determine that its bcz of missing permissions? I donot get a callback in this case for scan failure/successful. – Sameeksha Jain Jul 31 '20 at 17:59