private static final int HELLO_ID = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Date dat = new Date();//initializes to now
Calendar cal_alarm = Calendar.getInstance();
Calendar cal_now = Calendar.getInstance();
cal_now.setTime(dat);
cal_alarm.setTime(dat);
cal_alarm.set(Calendar.MONTH,3);
cal_alarm.set(Calendar.YEAR,2012);
cal_alarm.set(Calendar.DAY_OF_MONTH,4);
cal_alarm.set(Calendar.HOUR_OF_DAY,19);//set the alarm time
cal_alarm.set(Calendar.MINUTE, 15);
cal_alarm.set(Calendar.SECOND,0);
if(cal_alarm.before(cal_now)){//if its in the past increment
cal_alarm.add(Calendar.DATE,1);
}
Intent intent = new Intent(AlarmManagerTestActivity.this,
AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
AlarmManagerTestActivity.this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal_alarm.getTimeInMillis(), pendingIntent);
}
您好,我想在特定日期设置警报和通知,我正在使用此处给出的代码,但我无法在特定日期设置警报。请让我知道这里的错误是什么。
提前致谢