作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我设置了每天重复的闹钟。但它会有几秒钟或几分钟的错误。我怎样才能使它更准确?
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/
我是一名优秀的程序员,十分优秀!