I am currently using https://github.com/AltBeacon/android-beacon-library to detect iBeacon in app in service.
In my application, scan restart is performed every 6 seconds, and the monitoring cycle is set as follows.
beaconManager.setForegroundBetweenScanPeriod(0);
beaconManager.setForegroundScanPeriod(1100); // 1 second interval for group of measurements
beaconManager.setBackgroundBetweenScanPeriod(beaconManager.getForegroundBetweenScanPeriod()); // // set background same as foreground
beaconManager.setBackgroundScanPeriod(beaconManager.getForegroundScanPeriod());
Then the monitoring checks the region according to the didDetermineStateForRegion state.
public void startMonitoringBeaconsInRegion() {
if (beaconConsumer == null
|| !beaconManager.isBound(beaconConsumer)) {
Log.w(TAG, "Method startMonitoringBeaconsInRegion() invocation will be ignored.");
return;
}
refreshMode();
beaconManager.setNonBeaconLeScanCallback(this::nonBeaconLeScanCallback);
beaconManager.removeAllMonitorNotifiers();
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.i(TAG, "Did Enter Region");
}
@Override
public void didExitRegion(Region region) {
Log.i(TAG, "Did Exit Region");
isAdvertisingRefresh = true;
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "Did Determine State For Region");
try {
switch (state) {
case MonitorNotifier.INSIDE:
countContinueDetected_E_Beacon = 0;
countNotDetectedBeaconForStopAdv = 0;
Log.i(TAG, "INSIDE, Ranging is started");
beaconManager.startRangingBeaconsInRegion(region);
break;
case MonitorNotifier.OUTSIDE:
Log.i(TAG, "OUTSIDE, Ranging is stopped");
beaconManager.stopRangingBeaconsInRegion(region);
stopDoorOpenAdvertising();
break;
}
} catch (RemoteException e) {
e.printStackTrace();
unbind();
bind();
}
}
});
beaconManager.removeAllRangeNotifiers();
beaconManager.addRangeNotifier((beacons, region) -> didRangeBeacons(beacons));
try {
beaconManager.startMonitoringBeaconsInRegion(mRegion);
isMonitoringBeaconsInRegion = true;
} catch (RemoteException e) {
e.printStackTrace();
unbind();
bind();
}
Log.i(TAG, "Monitoring is started");
}
After running the application, monitoring starts and the corresponding message appears after a certain period of time.
Why do these messages keep appearing? Is there any way to get rid of it?
In addition to this, when launching the app, it keeps telling me that a BLE scan with the same settings has already been started in the app.
We are using BluetoothMedic in our application and we only monitor if monitoring is not started.
Please let me know how we can improve these issues as well. Thank you.