2011-06-02 6 views
0

J'ai 2 notification Statusbar dans mon application. Ces notifications apparaissent dans le même temps dans l'application, et je ne peux voir que la dernière notification. Et, si j'appuie sur le bouton Effacer, les deux sont effacés. Comment travailler avec plus d'une notification dans Android? La deuxième question est comment afficher le texte de la notification sur plusieurs lignes. Je ne peux voir que le début du texte.comment travailler avec 2 notifications dans Android?

Voici mon code:

pour la première notification:

setNotifiy private void() { notificationManager = (NotificationManager) getSystemService (Context.NOTIFICATION_SERVICE); CharSequence NotificationTicket = "Vous avez une notification";

CharSequence contentTitle = "You are close to " + name_shop + "!!!"; 
    CharSequence contentText = "So,you can go for shopping:)"; 

    long when = System.currentTimeMillis(); 

    Notification notification = new Notification(R.drawable.icon, 
      NotificationTicket, when); 

    Context context = getApplicationContext(); 

    Intent notificationIntent = new Intent(this, ShopsOnMap.class); 
    System.out.println("DDDDd" + lat_choose + "!!!"); 
    notificationIntent.putExtra("latshop", lat_choose); 
    notificationIntent.putExtra("longshop", long_choose); 

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
      notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    notification.setLatestEventInfo(context, contentTitle, contentText, 
      contentIntent); 

    notificationManager.notify(NOTIFICATION_ID, notification); 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

} 

et pour la deuxième notification:

private void hey (liste de chaînes) { notificationManager = (NotificationManager) getSystemService (Context.NOTIFICATION_SERVICE); CharSequence NotificationTicket = "Hé";

CharSequence contentTitle = "Shopping!!"; 
    CharSequence contentText = "Today,you must go for shopping for your list ' " 
      + list + "'" + "Don't forget!!!"; 

    long when = System.currentTimeMillis(); 

    Notification notification = new Notification(R.drawable.icon, 
      NotificationTicket, when); 

    Context context = getApplicationContext(); 

    Intent notifyIntent = new Intent(context, Lists.class); 

    PendingIntent intent = 
     PendingIntent.getActivity(Lists.this, 0, 
     notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); 

    notification.setLatestEventInfo(context, contentTitle, contentText, intent); 

    notificationManager.notify(NOTIFICATION_ID, notification); 

    notificationManager.notify(NOTIFICATION_ID, notification); 
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
} 

Répondre

0

Je vois que vos codes utilisent le même ID pour les deux notifications.

Comme vous le savez peut-être, la réponse est déjà sur cette documentation: Creating Status Bar Notifications.

Vous pouvez vous concentrer sur deux choses couvertes dans la documentation:

  1. ID de notification. Ceci est utile pour créer des notifications différentes.
  2. "Création d'une vue étendue personnalisée" pour créer une notification sur plusieurs lignes.
Questions connexes