gpt4 book ai didi

android - 每天准确重复报警(报警管理器)

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:23:14 26 4
gpt4 key购买 nike

我设置了每天重复的闹钟。但它会有几秒钟或几分钟的错误。我怎样才能使它更准确?

PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), notificationId, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 30);
long startUpTime = calendar.getTimeInMillis();
if (System.currentTimeMillis() > startUpTime) {
startUpTime = startUpTime + 24*60*60*1000;
}
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startUpTime, 24*60*60*1000 , pendingIntent);

最佳答案

尝试添加

calendar.set(Calendar.SECOND,00);

和改变

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startUpTime,  24*60*60*1000 , pendingIntent);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
startUpTime, AlarmManager.INTERVAL_DAY, pendingIntent);

关于android - 每天准确重复报警(报警管理器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28001154/

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