调度通知android

时间:2016-11-20 22:13:09

标签: android notifications

您好我正在尝试在Android中的特定时间生成通知。我能够生成通知,但它会立即生成,而我希望它稍后生成。任何人都可以建议我哪里出错。

calendar.set(Calendar.MONTH, 11);
calendar.set(Calendar.YEAR, 2016);
calendar.set(Calendar.DAY_OF_MONTH, 20);
calendar.set(Calendar.HOUR_OF_DAY, 2);
calendar.set(Calendar.MINUTE, 58);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM, Calendar.PM);

long timeinmill = calendar.getTime().getTime() - System.currentTimeMillis();
Intent myIntent = new Intent(MakeAppointment.this, MyReceiver.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(MakeAppointment.this, 0, myIntent,0);

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, timeinmill, pendingIntent);

1 个答案:

答案 0 :(得分:0)

不要减去当前时间。请参阅AlarmManager#RTC docs

timeinmill = calendar.getTime().getTime().