报警管理器没有在android中的确切时间触发报警

编程入门 行业动态 更新时间:2024-10-26 20:33:50
本文介绍了报警管理器没有在android中的确切时间触发报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用Calendar类别安排闹钟

I scheduled alarm using Calendar class as below

Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY,1); cal.getTimeInMillis(); cal.set(Calendar.MINUTE,05); long TriggerMillis = cal.getTimeInMillis(); AlarmManager aManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); aManager.set(AlarmManager.RTC_WAKEUP, TriggerMillis,pIntent);

其中pIntent是当警报触发时进一步处理的待处理意图。

where pIntent is an pending intent to proceed further when alarm triggers.

事件触发器有几秒钟的延迟。是使用Calendar类执行此任务的任何问题。有任何建议吗?

The event triggers with few seconds delay. Is that any problem using Calendar class for this task. Any suggestions?

TIA ..

推荐答案

  • 使用 _WAKEUP 闹钟服务直接。唯一可靠的模式包括 WakefulBroadcastReceiver ,我的 WakefulIntentService 或者沿着这些行的东西,其中

  • It is not reliable to use a _WAKEUP alarm with a service directly. The only reliable patterns involve WakefulBroadcastReceiver, my WakefulIntentService, or something along those lines, where the PendingIntent will be to a BroadcastReceiver.

    如果您的 android:targetSdkVersion 是19或更高版本,并且您正在运行在一个API级别19+的设备上, set()是不精确的。理想情况下,您允许它不精确,或者可以使用 setWindow()来控制它将如何关闭,以最小化您的报警事件的功率命中。如果它绝对必须在一个确切的时刻发生,您将需要使用 setExact()。由于 setWindow()和 setExact()是API第19级的新功能,您需要回退到<$在旧设备上,通过检查 Build.VERSION.SDK_INT 并相应分支

    If your android:targetSdkVersion is 19 or higher, and you are running on an API Level 19+ device, set() is inexact. Ideally, you allow it to be inexact, or perhaps use setWindow() to control how off it will be, to minimize the power hit of your alarm event. If it absolutely has to occur at a precise moment, you will need to use setExact(). Since setWindow() and setExact() are new to API Level 19, you will need to fall back to set() on older devices, by examining Build.VERSION.SDK_INT and branching accordingly.

  • 更多推荐

    报警管理器没有在android中的确切时间触发报警

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

    发布评论

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

    >www.elefans.com

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