setAlarmClock()在dozo模式下不适用于OPPO手机等少数设备

时间:2019-01-16 10:03:09

标签: android alarmmanager oppo setalarmclock

在我的应用程序中,我需要设置警报,当它们触发时,我试图在我的Receiver中触发它们。

为了处理棉花糖6.0中的Dozo模式,如果设备版本大于或等于6.0,我正在使用alarmManger.setAlarmClock()方法。除OPPO设备外,几乎所有设备都可以正常工作

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            final AlarmManager.AlarmClockInfo alarmClockInfo = new AlarmManager.AlarmClockInfo(fireDate.getTime(), pendingIntent);
            alarmManager.setAlarmClock(alarmClockInfo, pendingIntent);
            //alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, fireDate.getTime(), pendingIntent);
        } else {
            alarmManager.setExact(AlarmManager.RTC_WAKEUP, fireDate.getTime(), pendingIntent);
        }

================================================ ======================= 从终端,我得到了日志:adb shell dumpsys警报。

1。对于其他品牌(我的应用程序alarmManager.setAlarmClock()方法结果):

    Batch{b778e8c num=1 start=35988972 end=35988972 flgs=0x3}:
    RTC_WAKEUP #0: Alarm{b9e89d5 type 0 when 1547501400600 ######.######}
    tag=*walarm*:######.######.Reminder
            type=0 whenElapsed=+9h49m0s741ms when=2019-01-15 03:00:00
    window=0 repeatInterval=0 count=0 flags=0x3
    Alarm clock:
    triggerTime=2019-01-15 03:00:00
    showIntent=PendingIntent{3dc5ea: PendingIntentRecord{d66ec2a ######.###### broadcastIntent}}
    operation=PendingIntent{996c0db: PendingIntentRecord{d66ec2a ######.###### broadcastIntent}}

批处理是唯一的,并且标志值设置为0x3,这对于AlarmClocks而言将是这样。     对于大多数品牌,结果是相同的,但是在oppo中,标志设置为0x8

2。对于oppo手机(我的应用程序alarmManager.setAlarmClock()方法结果):

    Batch{b778e8c num=1 start=35988972 end=35988972 flgs=0x8}:
    RTC_WAKEUP #0: Alarm{b9e89d5 type 0 when 1547501400600 ######.######}
    tag=*walarm*:######.######.Reminder
            type=0 whenElapsed=+9h49m0s741ms when=2019-01-15 03:00:00
    window=0 repeatInterval=0 count=0 flags=0x8
    Alarm clock:
    triggerTime=2019-01-15 03:00:00
    showIntent=PendingIntent{3dc5ea: PendingIntentRecord{d66ec2a ######.###### broadcastIntent}}
    operation=PendingIntent{996c0db: PendingIntentRecord{d66ec2a ######.###### broadcastIntent}}

3。对于oppo手机(oppo默认警报应用):

    Batch{3450b8d num=1 start=464582537 end=464582537 flgs=0x9}:
    RTC_WAKEUP #0: Alarm{32536c5 type 0 when 1547690400000 ######.###### whenElapsed 464582537 windowLength 0 maxWhenElapsed 464582537 repeatInterval 0 action }
    tag=*walarm*:######.######.ALARM_ALERT
            type=0 whenElapsed=+17h4m45s187ms when=2019-01-17 07:30:00
    window=0 repeatInterval=0 count=0 flags=0x9
    Alarm clock:
    triggerTime=2019-01-17 07:30:00
    showIntent=PendingIntent{ee6881a: PendingIntentRecord{97c18f0 ######.###### startActivity (whitelist: 902f275:+30s0ms)}}
    operation=PendingIntent{3bc0f4b: PendingIntentRecord{2bd8d28 ######.###### broadcastIntent}}

在opp手机内部以接收警报,它应该是一个批处理,并且标记应设置为0x9

结论

其他电话:需要将标志= 0x3触发为警报,alarmManager.setAlarmClock()将标志设置为0x3,可以正常工作。

OPPO电话:需要标志= 0x9才能将其触发为警报。但是,alarmManager.setAlarmClock()会将标志设置为0x8。

在oppo设备中应该调用什么方法来将标志设为0x9?

0 个答案:

没有答案