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

前端之家收集整理的这篇文章主要介绍了android – 每天准确重复报警(报警管理器)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我每天都会重复闹钟.
但它会有几秒或几分钟的错误.
我怎样才能让它更准确?
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,pendingIntent);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,AlarmManager.INTERVAL_DAY,pendingIntent);
原文链接:https://www.f2er.com/android/309155.html

猜你在找的Android相关文章