Mark Dsylva
Mark Dsylva

Reputation: 42

How to know the status of BLE scan in android?

I am working on a mobile app where I am doing the following to get the data from my sensors.

  1. Running a BLE scan in the foreground service.
  2. Detect bluetooth on/off states and automatically starting and stopping the BLE scan.
  3. Restart BLE scan every 3mins (I read somewhere that BLE scans automatically stops when run more than 15mins). so just to be safe I am restarting it once every 3 mins.

I start/restart the scan using the following statement

scanner.startScan(scanFilters,scanSettings,callback);

I stop the scan using the following statement

scanner.stopScan(callback);

In scanFilters, I set the name of my device ID and In scanSettings I set the scan mode to LOW_LATENCY

The app works fine most of the time. But sometimes I get some complaints from my customers that eventhough bluetooth and location are on, there is no data update. The sensors are working fine. When I start a blueooth LE scan how to ensure that the scan is actually running or not?. I there anywhere that I can get a status of the scan running or no.

Upvotes: 2

Views: 1529

Answers (1)

Michael Kotzjan
Michael Kotzjan

Reputation: 2663

Since you are saying that this happens only for some customers there might be another source of your problem.

BLE needs the ACCESS_FINE_LOCATION permission to work for devices running an Android version lower than 8.0. Higher version can use the Device Companion Pairing. You might have added the Permission to your apps manifest file like this:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

But it is safer to also check for this permission at runtime and request it if not granted. Have a look at this page for more informations about how to request permissios from the user at runtime.

Upvotes: 1

Related Questions