I have an android app where I'm detecting beacons in foreground/background. Everything works fine excepting when I switch off the bluetooth on the device. In this case OnExitRegion it's called but I've to ignore it because I really don't know what the user is doing, but if then I move far of the beacon and switch on the bluetooth again, onExitRegion will not be called again and I won't know that I exited the region.
This is part of my code.
public class MyApplication extends Application implements BootstrapNotifier {
public void onCreate() {
super.onCreate();
...
mBeaconManager = BeaconManager.getInstanceForApplication(this);
mBeaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(Constants.BEACON_LAYOUT));
mBeaconRegion = new Region(Constants.BEACON_BACKGROUND_REGION, Identifier.parse(Constants.BEACON_UDID), null, null);
regionBootstrap = new RegionBootstrap(this, mBeaconRegion);
backgroundPowerSaver = new BackgroundPowerSaver(this);
mBeaconManager.setBackgroundScanPeriod(Constants.BEACON_BACKGROUND_SCAN_PERIOD);
mBeaconManager.setBackgroundBetweenScanPeriod(Constants.BEACON_BACKGROUND_BETWEEN_SCAN_PERIOD);
mBeaconManager.setAndroidLScanningDisabled(true);
...
}
I've tried to create a BroadcastReceiver for detecting when the bluetooth is off or on
public class BluetoothBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1)
== BluetoothAdapter.STATE_OFF) {
Log.w("BLUETOOTH", "Bluetooth is disconnected");
} else {
Log.w("BLUETOOTH", "Bluetooth is connected");
}
}
}
}
What I'd need is to check in this broadcastreceiver, when the bluetooth is on, if I'm still in the region or not to modify the UI.
Hope my explanation is clear enough.
Many thanks in advance!