【问题标题】:Get the alarm time which previously added to the AlarmManager获取之前添加到 AlarmManager 的闹钟时间
【发布时间】:2013-11-03 20:39:42
【问题描述】:

我使用 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);



}

【问题讨论】:

    标签: android alarmmanager android-alarms


    【解决方案1】:

    但我想从 alarmManger 中获取该时间并将其显示在应用程序中以获得更好的 UX 有什么方法可以获取闹钟时间?

    当您设置事件时,您自己将其保存在某个持久性位置(文件、数据库、SharedPreferences)。 AlarmManager 是只写的;您无法从中检索有关预定事件的信息。

    【讨论】:

      猜你喜欢
      • 2017-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 2013-10-25
      相关资源
      最近更新 更多