フォアグラウンド/バックグラウンドでビーコンを検出している Android アプリがあります。デバイスのBluetoothをオフにする場合を除いて、すべて正常に動作します。この場合、OnExitRegion が呼び出されますが、ユーザーが何をしているのか本当にわからないので無視する必要がありますが、ビーコンから離れて Bluetooth を再度オンにすると、onExitRegion は再度呼び出されず、私がその地域を出たことを知りません。
これは私のコードの一部です。
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);
...
}
Bluetoothがオフまたはオンになっていることを検出するためのBroadcastReceiverを作成しようとしました
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");
}
}
}
}
私が必要とするのは、ブルートゥースがオンのときに、このブロードキャストレシーバーをチェックインすることです。まだその地域にいる場合、または UI を変更しない場合です。
私の説明が十分に明確であることを願っています。
よろしくお願いします!