我正在使用 Calendar 类来获取当前日期和时间。然后我设置警报的日期和时间,并将信息传递给 AlarmManager 对象。我有一个“设置警报”按钮单击它应该设置警报,不知何故单击该按钮没有反馈。
Button btnOpen = (Button) findViewById(R.id.btnSetAlarm);
btnOpen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
timePicker = (TimePicker) findViewById(R.id.timePicker);
datePicker = (DatePicker) findViewById(R.id.datePicker);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, datePicker.getYear());
calendar.set(Calendar.MONTH, datePicker.getMonth());
calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute());
calendar.set(Calendar.SECOND, 0);
PendingIntent displayIntent = PendingIntent.getActivity(
getBaseContext(), 0,
new Intent("my.todo.list.ShowNotification"), 0);
alarmManager.set(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), displayIntent);
}
});
}
我使用的是安卓版本 4.0.1
谢谢。