我正在尝试发出一个会在指定的 n 次响起的警报。我的代码如下。我能够正确获取条目,但根本没有警报响起。
public void setAlert(View view) {
int h[] = new int[TOTAL_ALARMS];
int m[] = new int[TOTAL_ALARMS];
Intent intent[] = new Intent[TOTAL_ALARMS];
PendingIntent pendingIntent[] = new PendingIntent[TOTAL_ALARMS];
int piID = 12345;
Calendar[] cal = new Calendar[TOTAL_ALARMS];
for (int i = 0; i < TOTAL_ALARMS; i++) {
cal[i] = Calendar.getInstance();
}
for (int i = 0; i < TOTAL_ALARMS; i++) {
try {
m[i] = Integer.parseInt(editHour[i].getText().toString());
h[i] = Integer.parseInt(editMinute[i].getText().toString());
cal[i].set(Calendar.HOUR, h[i]);
cal[i].set(Calendar.MINUTE, m[i]);
intent[i] = new Intent(this, AlarmService.class);
pendingIntent[i] = PendingIntent.getActivity(this,
piID++, intent[i], PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,
cal[i].getTimeInMillis(), pendingIntent[i]);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
} catch (Exception ex) {
ex.printStackTrace();
System.out.print("OOPS!");
}
}
}