0

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

Community
  • 1
  • 1
Klimoma
  • 11
  • 2
  • Please show that broadcast receiver code. Is your broadcast receiver called when outside of doze mode? – davidgyoung Feb 11 '19 at 12:20
  • I put code of my broadcastReceiver into question. Broadcast is called before puting phone into doze mode. After wake up is never called again. – Klimoma Feb 11 '19 at 12:31
  • Does your broadcast receiver get called again once you are out of doze mode using the same scan started before doze mode was entered? if no, if you restart the scan after exiting doze, does it start calling your broadcast receiver again? – davidgyoung Feb 11 '19 at 16:19
  • After restart of scat it is scanning again. – Klimoma Feb 12 '19 at 11:46
  • i am really confused right now. I tried it on second phone Google Pixel with android 9.0 and scannning is working in and out of the doze mode, but its stop working when i turn screen off. – Klimoma Feb 12 '19 at 11:46

0 Answers0