アプリケーションで 2 つの特定の時間に 1 日に 2 つの通知を表示したいのですが、今までは 1 つの通知しか表示できませんでした。これは私のコードです。複数の通知を表示するにはどうすればよいですか。たとえば、1 つは午前 7 時、もう 1 つは午後 6 時ですか?
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 メソッドの MyAlarmService で呼び出しました
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);