如何同时显示两个单独的通知?

时间:2013-03-18 20:04:05

标签: android alarmmanager notificationmanager

我的应用程序需要在需要服用药物时在状态栏中显示通知。如果要同时服用两粒药丸,则应出现两个通知。现在,如果药丸时间不同,我的应用程序可以显示单独的通知。问题是如果它们同时只显示最近创建的那个(当我按下按钮时)。然而,它仍然振动两次。有什么建议吗?

信息类:

    DatabaseHelper notiDb = new DatabaseHelper(this);
    notiDb.open();
    final String dataName = notiDb.getDataName(pushed_name);
    String dataDaily = notiDb.getDataDaily(pushed_name);
    final String dataWeekly = notiDb.getDataWeekly(pushed_name);
    String dataTwice = notiDb.getDataTwice(pushed_name);
    final String dataDosage = notiDb.getDataDosage(pushed_name);
    String dataStart = notiDb.getDataStart(pushed_name);
    String dataID = notiDb.getDataID(pushed_name);
    notiDb.close();

     ID = Integer.parseInt(dataID);
     int value_Weekly = Integer.parseInt(dataWeekly);
     int value_Daily = Integer.parseInt(dataDaily);
     int value_Twice = Integer.parseInt(dataTwice);
     int value_Start = Integer.parseInt(dataStart);

     Calendar calendar = Calendar.getInstance();
     calendar.set(Calendar.HOUR_OF_DAY, value_Start);
     calendar.set(Calendar.MINUTE, 00);
     calendar.set(Calendar.SECOND, 00);
     int setTime = (value_Daily*value_Twice)/value_Weekly;



     Intent intent_noti = new Intent(this,Alarm.class);
     intent_noti.putExtra("ID", ID);
     intent_noti.setData(Uri.parse(intent_noti.toUri(Intent.URI_INTENT_SCHEME)));
     PendingIntent pendingIntent = PendingIntent.getActivity(this, ID, intent_noti, PendingIntent.FLAG_ONE_SHOT);
     AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
     am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), setTime, pendingIntent);

警报类:

    DatabaseHelper notiDb = new DatabaseHelper(this);
    notiDb.open();
    final String dataName = notiDb.getDataName(pushed_name);
    String dataDaily = notiDb.getDataDaily(pushed_name);
    String dataWeekly = notiDb.getDataWeekly(pushed_name);
    String dataTwice = notiDb.getDataTwice(pushed_name);
    String dataDosage = notiDb.getDataDosage(pushed_name);
    String dataStart = notiDb.getDataStart(pushed_name);
    String dataID = notiDb.getDataID(pushed_name);
    notiDb.close();

    ID = Integer.parseInt(dataID);


   Intent intent_unique = new Intent(this, NotiScenario.class);
   intent_unique.putExtra("ID", ID);
   intent_unique.setData(Uri.parse(intent_unique.toUri(Intent.URI_INTENT_SCHEME)));
   PendingIntent pIntent = PendingIntent.getActivity(this, ID, intent_unique, 0);


    // Build notification
    Notification noti = new Notification.Builder(this)
        .setContentTitle("MedScan")
        .setContentText("3. You should take "+dataDosage +" pills of " +dataName)
        .setSmallIcon(R.drawable.original)
        .setContentIntent(pIntent)
       .build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    noti.defaults |= Notification.DEFAULT_ALL;
     //Hide the notification after its selected
   noti.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(ID, noti);

1 个答案:

答案 0 :(得分:1)

通知的ID是否相同?如果这是真的,我认为这会导致覆盖通知。如果要同时显示多个通知,请使用不同的ID。