Detectign a beacon in Oreo after waking up from Doze mode

222 Views Asked by At

am trying to wake up my foreground service with http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8#the-new-way-fast-detections

Expected behavior

See first beacon and send PendingIntent to BroadcastReceiver which is starting my foreground service with BeaconConsumer.

Actual behavior

After doze mode nothing is called.

Steps to reproduce this behavior

Using same code which is here: http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8#the-new-way-fast-detections than put phone to doze mode and back terminal:

adb shell dumpsys deviceidle force-idle

adb shell dumpsys deviceidle unforce

broadcastReceiver code:

class BluetoothScanReceiver: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
    val bleCallbackType = intent.getIntExtra(BluetoothLeScanner.EXTRA_CALLBACK_TYPE, -1)
    if (bleCallbackType != -1) {
        val scanResults = intent.getParcelableArrayListExtra<Parcelable>(
                BluetoothLeScanner.EXTRA_LIST_SCAN_RESULT)
        println("xxxxx BluetoothScanReceiver onreceive ")
        context.startBeaconScanning()
    }
}

}

Inicialization of Ble Scanner

val settings = ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER).build()
val bluetoothManager = applicationContext.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
val bluetoothAdapter = bluetoothManager.adapter
val i = Intent(applicationContext, BluetoothScanReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, i, FLAG_UPDATE_CURRENT)
val scanner = bluetoothAdapter.bluetoothLeScanner
scanner.startScan(null, settings, pendingIntent)

Mobile device model and OS version

Nokia 5 - Android 8.1

What should i do to start my foreground service when i see first beacon even if my app is killed/in doze mode/after doze mode?

Thank you

0

There are 0 best solutions below