Android打ze模式 [英] Android doze mode

查看:144
本文介绍了Android打ze模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我将使用警报通知用户事件,问题是Android版本6.x上的
-

警报在确切时间的相同分钟后发出。

仅当设备进入睡眠模式时。

In My app I'll use an Alarm to notify user for event, the problem is on Android version 6.x-
The alarm is delivered after same minutes of the exact times.
This is only when the device enter on sleeping mode.

我试图在报警之前唤醒设备,但无济于事。

I tried to wakelock the device before the alarm, but to no avail.

有人可以帮助我吗?这是我的代码

Can anyone help me? this is my code

设置闹钟

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alarmCalendar.getTimeInMillis(), pendingIntent);
        if (minutesBefore > 0) {
            beforeCalendar.add(Calendar.MINUTE, -minutesBefore);
            alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, beforeCalendar.getTimeInMillis(), beforePendingIntent);
        }
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmCalendar.getTimeInMillis(), pendingIntent);
        if (minutesBefore > 0) {
            beforeCalendar.add(Calendar.MINUTE, -minutesBefore);
            alarmManager.setExact(AlarmManager.RTC_WAKEUP, beforeCalendar.getTimeInMillis(), beforePendingIntent);
        }
    } else {
        alarmManager.set(AlarmManager.RTC_WAKEUP, alarmCalendar.getTimeInMillis(), pendingIntent);

        if (minutesBefore > 0) {
            beforeCalendar.add(Calendar.MINUTE, -minutesBefore);
            alarmManager.set(AlarmManager.RTC_WAKEUP, beforeCalendar.getTimeInMillis(), beforePendingIntent);
        }
    }

弱锁


当我通过广播接收器收到警报时,我试图通过此代码从打do模式唤醒设备

when i receive the alarm by broadcastreceiver im try to wake up device from doze mode by this code



PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        //Object flags;

            wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Alarm_WakeLock");

        wl.acquire();

但是在相同的分钟后仍会发出警报!

But the alarm still delivered after same minutes!!

推荐答案

当手机不使用一段时间后,实施休眠模式可以节省电池电量。

Doze mode is implemented to save the battery when the phone isn't used for some time. It does that by holding off operations like the AlarmManager.

如果确实需要在准确的时间触发警报,请使用[ setExactAndAllowWhileIdle( )]( https:// developer .android.com / reference / android / app / AlarmManager.html#setExactAndAllowWhileIdle(int ,long,android.app.PendingIntent))。

If you really need the alarm to be fired in an exact time, use [setExactAndAllowWhileIdle()](https://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int, long, android.app.PendingIntent)).

The <一个href = https://developer.android.com/training/monitoring-device-state/doze-standby.html#understand_doze rel = nofollow>文档说:


如果您需要设置在打ze睡时触发的警报,请使用setAndAllowWhileIdle()或setExactAndAllowWhileIdle()。

If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().

这篇关于Android打ze模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆