android - 获取之前添加到AlarmManager中的闹钟时间

标签 android alarmmanager android-alarms

我使用 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/

相关文章:

android - 在 webview 上显示进度对话框

android - Alarmmanager - 每分钟发生火灾警报

android - 由于缺少 keystore.properties 文件,Gradle 构建失败

android - 如何在 Android Q 屏幕锁定时从广播接收器启动 Activity

android - Firebase 发出太多警报

java - 如何将数组转换为 Android 资源?

android - 如何通过异步任务传递参数?

android - 如何在钛合金的ListView中仅根据单词的第一个字母进行过滤来搜索?

android - 设置 AlarmManager 的最佳时机/位置

android - android如何比较挂起的 Intent