我正在尝试在一天中的特定时间设置闹钟,例如:20:15。以下是我正在使用的代码,但它不会在20:15响起。
Intent intent = new Intent(AlarmActivity.this, MyBroadcastReceiver.class);
intent.putExtra("Hekma", "One better than none");
PendingIntent pintent = PendingIntent.getService(AlarmActivity.this, 0,intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 20);
cal.set(Calendar.MINUTE, 15);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
alarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pintent);