2013-03-18 52 views
0

無論何時需要吃藥,我的應用程序需要在狀態欄中顯示通知。如果同時服用兩顆藥丸,則會出現兩個通知。現在我的應用程序可以顯示單獨的通知,如果藥片時間不同。問題是如果它們同時只顯示最近創建的那個(當我按下按鈕時)。但它仍然振動兩次。有什麼建議麼?如何同時顯示兩個單獨的通知?

信息類:

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

是通知的相同的ID?如果這是真的,我認爲這會導致通知的重寫。如果您顯示多個通知並排顯示,請使用不同的ID。

+0

沒有這些ID是唯一的。我檢查確認他們是不同的。對於其中一個藥丸其「1」,而另一個是「2」 – anaconda122 2013-03-18 20:55:14

相關問題