我无法设置闹钟日历

时间:2012-04-23 20:52:13

标签: android calendar set alarmmanager alarm

我正在尝试为我的课程设置闹钟。我需要在他们开始前1小时发出警报。所以我只想要

  • 获得一年中的一周
  • 浏览几周(循环...... 51,52)
    • 查看类(循环... n)
      • 设定此课程的星期几
      • 在此课程前一小时设置小时
      • 将分钟设置为00
      • 使用此日历实例设置闹钟
    • 循环结束(类)
    • 将当周设置为当前一周的一周

Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
for (int i = cal.get(Calendar.WEEK_OF_YEAR); i <= 52; i++) {
    for (Dersler d : dersProgrami) {
        alarm = new DersAlarmi(String.valueOf(d.getBaslangicS()) + "00", d.getDersAdi(), d.getDerslik());
        cal.set(Calendar.DAY_OF_WEEK, d.getDayOfClass()+1);
        cal.set(Calendar.MINUTE, 00);
        cal.set(Calendar.HOUR_OF_DAY, d.getStartHour());
        cal.add(Calendar.HOUR_OF_DAY, -1);
        Log.i("ALARM KURULDU",
            String.valueOf(i) + String.valueOf(cal.get(Calendar.DAY_OF_MONTH))+"."+String.valueOf(cal.get(Calendar.MONTH))+"."+String.valueOf(cal.get(Calendar.YEAR))+" "+String.valueOf(cal.get(Calendar.HOUR_OF_DAY))+":"+String.valueOf(cal.get(Calendar.MINUTE))+" Ders:" + d.getDersAdi()
                + " Hafta:"
                + cal.get(Calendar.WEEK_OF_YEAR) + " Gün:"
                + cal.get(Calendar.DAY_OF_WEEK) + " Saat:"
                + cal.get(Calendar.HOUR_OF_DAY));
            alarmManager.set(AlarmManager.RTC_WAKEUP,
                cal.getTimeInMillis(), pendingIntent);
        dersAlarmlari.add(alarm);
    }
    cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR)+1);
}

当前日期时间是:2012年4月23日23:37

Logcat是:

04-23 23:23:10.835: I/ALARM KURULDU(16380): 17 25.3.2012 14:0 Ders:DATA MINING Hafta:17 Gün:4 Saat:14

04-23 23:23:10.835: I/ALARM KURULDU(16380): 17 23.3.2012 8:0 Ders:Database Management and SQL Hafta:17 Gün:2 Saat:8

04-23 23:23:10.855: I/ALARM KURULDU(16380): 17 25.3.2012 12:0 Ders:ENTREPRENEURSHIP Hafta:17 Gün:4 Saat:12

04-23 23:23:10.865: I/ALARM KURULDU(16380): 1723.3.2012 11:0 Ders:GRADUATION PROJECT Hafta:17 Gün:2 Saat:11

04-23 23:23:10.865: I/ALARM KURULDU(16380): 18 25.3.2012 14:0 Ders:DATA MINING Hafta:17 Gün:4 Saat:14

04-23 23:23:10.885: I/ALARM KURULDU(16380): 18 23.3.2012 8:0 Ders:Database Management and SQL Hafta:17 Gün:2 Saat:8

04-23 23:23:10.885: I/ALARM KURULDU(16380): 18 25.3.2012 12:0 Ders:ENTREPRENEURSHIP Hafta:17 Gün:4 Saat:12

04-23 23:23:10.895: I/ALARM KURULDU(16380): 18 23.3.2012 11:0 Ders:GRADUATION PROJECT Hafta:17 Gün:2 Saat:11

04-23 23:23:10.905: I/ALARM KURULDU(16380): 19 25.3.2012 14:0 Ders:DATA MINING Hafta:17 Gün:4 Saat:14

...

那么为什么它在logcat而不是今天的日期23中表示23. 03 .2012或25. 03 。2012. 04 0.2012?我一直在浪费我的时间,有人能告诉我正确设置闹钟的方法吗?

1 个答案:

答案 0 :(得分:2)

您正在使用它来打印月份:cal.get(Calendar.MONTH))

然而,返回的月份看起来是零索引。

根据日历联机帮助页,JANUARY的值为0,APRIL的值为3.因此,如果您要打印通常打印的月份(4月= 4) ,然后只需在打印前的一个月添加一个。