【问题标题】:Notification in Android before the specified date在指定日期之前在 Android 中通知
【发布时间】:2012-10-18 07:03:43
【问题描述】:

我创建了一个假设“我的考试”的通知。

我想在设定日期前 3 天显示提醒通知

我正在将日期存储在数据库中,希望将其与当前日期进行比较并显示通知

任何帮助将不胜感激

谢谢...

【问题讨论】:

  • 它对我来说像这样工作:当我从 datepicker 中选择值时,比如 int day = picker.getDayOfMonth(); int 月 = picker.getMonth(); int year = picker.getYear(); i;将采用一个值为 3 的 int 变量和 i';;像这样从日历中减去日历 c = Calendar.getInstance(); c.set(年、月、日);并调用通知它工作正常,但现在的问题是,如果我的日期是本月 1 日,那么减法逻辑将不起作用,我们将不胜感激:)

标签: java android android-intent notifications alarmmanager


【解决方案1】:

要生成比特定日期早 3 天的日期,请尝试以下操作:

Calendar c = Calendar.getInstance();
c.set(year, month, day); // Set the calendar NOTE: this will not change the hour, minute, second
c.add(Calendar.DAY_OF_YEAR, -3); // Roll the calendar back 3 days

【讨论】:

  • 我要找的东西,tx
猜你喜欢
  • 2016-02-10
  • 1970-01-01
  • 2014-07-09
  • 2012-04-13
  • 2012-11-13
  • 2022-08-09
  • 1970-01-01
  • 2016-04-14
  • 2021-01-27
相关资源
最近更新 更多