0
我想在2个特定时间内在我的应用程序中每天显示2个通知,直到现在我只能够显示一个通知。 这是我的代码,我如何显示多个通知。 一个在上午7点,另一个在下午6点例如?在Android中使用闹钟管理器每天显示多个通知
Intent myIntent = new Intent(Calender.this, MyAlarmService.class);
int id = (int) System.currentTimeMillis();
pendingIntent = PendingIntent.getService(Calender.this, id,
myIntent, Notification.FLAG_ONLY_ALERT_ONCE);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar timeToSet = Calendar.getInstance();
timeToSet.set(Calendar.HOUR_OF_DAY, hour);
alarmManager.set(AlarmManager.RTC_WAKEUP,
timeToSet.getTimeInMillis(), pendingIntent);
我在OnStart方法
final Calendar c = Calendar.getInstance();
Notification note = new Notification(R.drawable.icon,
getString(R.string.app_name), System.currentTimeMillis());
Intent intent = new Intent(this, Calender.class);
PendingIntent i = PendingIntent.getActivity(this, 0, intent,
Notification.FLAG_ONGOING_EVENT);
note.setLatestEventInfo(this, getString(R.string.app_name),
"Some String", i);
note.flags |= Notification.FLAG_AUTO_CANCEL;
NOTIFY_ME_ID = System.currentTimeMillis();
mgr.notify((int) NOTIFY_ME_ID, note);
设置警报管理器两次。 –
我应该调用所有的代码行再次设置警报或alarmManager.set(AlarmManager.RTC_WAKEUP, timeToSet.getTimeInMillis(),pendingIntent); ? – Reham
我认为是的,再次定义'timeToSet',这次例如是6PM,并为新的时间设置'alarmManager.set(....)'。 –