-
Notifications
You must be signed in to change notification settings - Fork 2
Scanning Beacons
Michał Gasztold edited this page Sep 10, 2020
·
6 revisions
It is mandatory to ask user for location permission on the app level if running on Android 6 or higher:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ContextCompat.checkSelfPermission(
applicationContext,
Manifest.permission.ACCESS_FINE_LOCATION
)
!= PackageManager.PERMISSION_GRANTED
) {
val permissions: Array<String> = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.FOREGROUND_SERVICE, // for scanning in the background
Manifest.permission.ACCESS_BACKGROUND_LOCATION // for scanning in the background
)
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.FOREGROUND_SERVICE // for scanning in the background
)
} else {
arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION
)
}
}
requestPermissions(permissions, REQUEST_CODE_PERMISSION_LOCATION)
}
It is possible to customize Bluetooth LE scanning settings by using the following methods of UbuduIndoorLocationManager:
/**
* Minimum detection distance for a beacon to be taken into account in position calculations
* @param meters threshold in meters
*/
public void setAccuracyThreshold(int meters);
/**
* Minimum detection signal strength (RSSI) for a beacon to be
* taken into account in position calculations
* @param rssi threshold in dBm
*/
public void setRssiThreshold(int rssi);
public void setForegroundScanPeriod(long periodMillis);
public void setForegroundBetweenScanPeriod(long periodMillis);
public void setBackgroundScanPeriod(long periodMillis);
public void setBackgroundBetweenScanPeriod(long periodMillis);
In order to make SDK keep calculating positions when app is in background for longer period of time it is possible to activate foreground service for maintaining the scanner:
mIndoorLocationManager.setBackgroundOperationEnabled(true, foregroundServiceNotification);
Note: It is mandatory to call this before calling mIndoorLocationManager.start(mUbuduStartCallback) method.