从打ze模式唤醒后,在奥利奥(Oreo)中检测信标

时间:2019-02-11 12:04:42

标签: android mode beacon doze

am试图用http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8#the-new-way-fast-detections唤醒我的前台服务

预期行为

查看第一个信标,然后将PendingIntent发送到BroadcastReceiver,后者将通过BeaconConsumer启动我的前台服务。

实际行为

打ze模式后什么也没叫。

重现此行为的步骤

使用以下相同的代码:http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8#the-new-way-fast-detections 而不是让手机进入打ze模式并返回 终端:

  

adb shell dumpsys deviceidle force-idle

     

adb shell dumpsys deviceidle解除强制

broadcastReceiver代码:

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()
    }
}

}

Ble扫描仪的初始化

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)

移动设备型号和操作系统版本

诺基亚5-Android 8.1

即使我的应用程序被杀死/处于打mode模式/打after后模式,我仍然看到我第一个信标我应该怎么做?

谢谢

0 个答案:

没有答案