androidbluetoothbluetooth-lowenergyaltbeaconandroid-doze

Android check is bluetooth in doze mode


Good day. I would like to know if the bluetooth scanning is unavailable now (locked by doze mode?).

Now i check it by this method:

fun isInDozeMode(context: Context) : Boolean {
    val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && powerManager.isDeviceIdleMode
}

But this method returns true even if i receive bluetooth (iBeacon) event just now.


Solution

  • Bluetooth is not directly affected by Doze mode:

    Doze does not affect the ability to do bluetooth scans or run Handler-based timers, but it does affect the ability to use the Android AlarmManager system, which some beacon-based systems use to schedule bluetooth scans. For apps based on the Android Beacon Library, the disabling of Alarms does not cause problems in scanning for beacons because it only uses Alarms as a backup should Handler-based timers fail. Tests on a Nexus 9 running the third preview release of Android M (build number MPA44l) show that beacon detection continues normally under Doze.

    See my blog post here. While that blog post was written for Android 6.0, subsequent doze changes added in 7.0 also do not affect Bluetooth scanning. See here.