gpt4 book ai didi

java - Android AlarmManager 与 SQL

转载 作者:太空宇宙 更新时间:2023-11-04 09:44:44 26 4
gpt4 key购买 nike

我有一个项目,它使用 SQLite 数据库在数据库的特定时间触发警报,我在项目中使用 android 警报管理器,并使用广播接收器在启动时管理警报,这里是 AlarmCode 的示例:

alarmIntent = PendingIntent.getBroadcast(context, ALARM_ID, intent, 
PendingIntent.FLAG_CANCEL_CURRENT);

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
//lollipop_mr1 is 22, this is only 23 and above
// alarmMgr.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, then.getMillis()-G.AzanDelayTime, alarmIntent);
alarmMgr.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, then.getMillis(), alarmIntent);


} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
//JB_MR2 is 18, this is only 19 and above.
//alarmMgr.setExact(AlarmManager.RTC_WAKEUP, then.getMillis()-G.AzanDelayTime, alarmIntent);
alarmMgr.setExact(AlarmManager.RTC_WAKEUP, then.getMillis(), alarmIntent);
}
else if (Build.VERSION.SDK_INT >= 21) {

alarmMgr.setAlarmClock(new AlarmManager.AlarmClockInfo(then.getMillis(), alarmIntent), alarmIntent);
Toast.makeText(G.context,"This is sdk>21",Toast.LENGTH_LONG).show();

}
else {
//available since api1
//alarmMgr.set(AlarmManager.RTC_WAKEUP, then.getMillis()-G.AzanDelayTime, alarmIntent);
alarmMgr.set(AlarmManager.RTC_WAKEUP, then.getMillis(), alarmIntent);

但我希望每个设备上的闹钟都能在准确的时间触发,在某些情况下,闹钟会在 15 分钟或更短的时间内触发,此问题的最佳解决方案是什么?

最佳答案

您可以使用AlarmManagerCompat :

AlarmManagerCompat.setExactAndAllowWhileIdle(...)

AlarmManagerCompat.setAlarmClock(...)

关于java - Android AlarmManager 与 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55556545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com