它是关于一个小型 android 应用程序,它将在一周中的每一天花费数小时作为用户的输入,并在相应的日子相应地打开/关闭蓝牙设备,而不管“日期”如何。即代码应该只检查日期、小时和分钟。我使用了以下代码(用于今天即星期五的测试目的),但它不会触发警报。
//..........setting calender for MyAlarmService
Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR));
cal.set(Calendar.HOUR_OF_DAY, 11);
cal.set(Calendar.MINUTE, 5);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, cur_cal.get(Calendar.MILLISECOND));
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE));
cal.set(Calendar.MONTH, cur_cal.get(Calendar.MONTH));
// here it m setting the "Today"
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
当我删除语句 cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
AlarmService 在上面指定的时间(即上午 11:05)完美触发“今天”
我究竟做错了什么?