我正在使用以下代码在特定日期和时间设置警报。
mCalendar.setTimeInMillis(System.currentTimeMillis());
mCalendar.set(Calendar.YEAR, 2013);
mCalendar.set(Calendar.MONTH, 0);
mCalendar.set(Calendar.DAY_OF_MONTH, 16);
mCalendar.set(Calendar.HOUR_OF_DAY, 1);
mCalendar.set(Calendar.MINUTE, 30);
mCalendar.set(Calendar.SECOND, 0);
mCalendar.set(Calendar.MILLISECOND, 0);
new ReminderManager(this).setReminder(info.id, mCalendar);
功能ReminderManager.setReminder
是:
public void setReminder(Long taskId, Calendar when)
{
Intent i = new Intent(mContext, OnAlarmReceiver.class);
i.putExtra(DataBaseHelper.KEY_ROWID, (long)taskId);
PendingIntent pi = PendingIntent.getBroadcast (mContext,0,i,PendingIntent.FLAG_ONE_SHOT);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);
}
它无法正常工作,当我在我的应用程序中按下“放置提醒”菜单项而不是我指定的时间时,警报会响起。