如何在Android 4.4中设置准确,重复的警报? [英] How can I set exact, repeating alarms in Android 4.4?

查看:105
本文介绍了如何在Android 4.4中设置准确,重复的警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在设置这样的警报:

Right now, I am setting alarms like this:

        AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, AlarmReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

        timedate = cal.getTime();

        //convert date to milis
        long timeInMilis = (timedate.getTime());

        //Set Alarm to Repeat
        manager.setRepeating(AlarmManager.RTC_WAKEUP, timeInMilis, interval, pendingIntent);

不幸的是,重复的预定时间是不准确的,我读到他们可能在完整的时间间隔内不准确!

Unfortunately, the scheduled times for repeating are inexact and I read that they could be inexact for a full interval!

所以,我想切换到设置一个确切的重复警报。我的设备至少需要最新的API 19 / Android 4.4,因此我无法使用setRepeating。

So, I would like to switch over to seting an exact repeating alarm. My device requires a minimum only of the latest API 19/Android 4.4, so I can't use setRepeating.

我可以做些什么来设置精确的重复警报?

What can I do instead to set an exact repeating alarm?

推荐答案


不幸的是,重复的预定时间是不准确的,我读到它们可能是不准确的一个完整的间隔!

Unfortunately, the scheduled times for repeating are inexact and I read that they could be inexact for a full interval!

如果你的 targetSdkVersion 是19或更高,是的。

If your targetSdkVersion is 19 or higher, yes.


我可以做些什么来设置精确的重复警报?

What can I do instead to set an exact repeating alarm?

使用 setExact()来控制初始延迟。然后,作为处理该事件的工作的一部分,使用 setExact()在下一个所需时间获得控制权。 IOW,你自己做重复部分。

Use setExact() to get control for your initial delay. Then, as part of your work for processing that event, use setExact() to get control at your next desired time. IOW, you do the "repeating" part yourself.

是的,这很烦人。

这是故意的刺激性,引导开发人员使用精确的重复警报,因为那些电池比他们不精确的兄弟更糟糕。如果用户会察觉到不准确的行为并且不会欣赏它,请随意使用 setExact()以在用户想要时发出警报。但是,如果用户不会察觉到不准确的行为,请使用不准确的警报,因为用户可能会注意到确切警报对电池的影响。

It is intentionally irritating, to steer developers to not use exact repeating alarms, as those are worse for the battery than are their inexact brethren. If the user will perceive the inexact behavior and will not appreciate it, feel free to use setExact() to make the alarms occur when the user wants. However, if the user will not perceive the inexact behavior, please use inexact alarms, as the user may notice the battery impact of your exact alarms.

这篇关于如何在Android 4.4中设置准确,重复的警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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