如何在Android 4.4中设置准确,重复的警报?

编程入门 行业动态 更新时间:2024-10-10 15:20:06
本文介绍了如何在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中设置准确,重复的警报?

本文发布于:2023-11-27 11:38:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   准确   如何在   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!