我使用 AlarmManager 类每天在特定时间通知用户(用户将从时间选择器中选择时间) 一切都很好 al7mdllah ^^ 但我想从 AlarmManger 获取该时间并将其显示在应用程序中以获得更好的用户体验 有什么办法可以获取闹钟时间吗?
这是我的代码
public void witer_reminder(View view)
{
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, Witer_Notification.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
Calendar calSet = (Calendar) cal.clone();
calSet.set(Calendar.HOUR_OF_DAY, picker.getCurrentHour());
calSet.set(Calendar.MINUTE,picker.getCurrentMinute());
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
if(calSet.compareTo(cal) <= 0){
//Today Set time passed, count to tomorrow
calSet.add(Calendar.DATE, 1);
}
am.setRepeating(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(),
24*60*60*1000, pendingIntent);
}
最佳答案
But I want to get that time from the alarmManger and display it in the application to get a better UX is there any way to get the alarm time?
当您设置事件时,将其保存在某个永久位置(文件、数据库、SharedPreferences)。 AlarmManager
是只写的;您无法从中检索有关预定事件的信息。
关于android - 获取之前添加到AlarmManager中的闹钟时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19757823/