0

我想在我的应用程序中每天在 2 个特定时间显示 2 个通知,直到现在我只能显示一个通知。这是我的代码,我怎样才能显示多个通知。例如早上 7 点一个,下午 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);
4

1 回答 1

0

您应该为不同的通知设置不同的键。如果您将一个键用于多个通知,它将重写同一个。

于 2013-07-27T12:24:20.480 回答