Comment créer Plusieurs barre de Notifications sous android
J'ai besoin de créer plusieurs barre de notifications. Quand j'ai tirer vers le bas la barre d'état, plusieurs icônes de notification devraient être affichés sous forme de liste. Chaque icône de notification devrait montrer séparer les données à afficher sur la page suivante.Comment pourrais-je faire cela?
Mon code:
public class SimpleNotification extends Activity {
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
String str="Hai";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis());
Button start = (Button)findViewById(R.id.notifyButton);
Button cancel = (Button)findViewById(R.id.cancelButton);
start.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Context context = getApplicationContext();
CharSequence contentTitle = "Notification Details...";
CharSequence contentText = "Browse Android Official Site by clicking me";
Intent notifyIntent = new Intent(SimpleNotification.this,
sub.class);
Bundle bundle = new Bundle();
bundle.putString("welcome",str);
notifyIntent.putExtras(bundle);
PendingIntent intent =
PendingIntent.getActivity(SimpleNotification.this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
}
});
Ici je l'ai fait pour une notification, mais j'ai besoin de créer plusieurs notifications que chaque notification doit montrer à chacun de données.
- Double Possible de notifications Multiples pour la même activité
Vous devez vous connecter pour publier un commentaire.
Vous avez besoin pour passer un ID unique à chaque notification. Une fois que vous avez cliqué sur l'annonce vous utilisez l'IDENTIFIANT de l'enlever.
MyActivityA - dans onCreate()
Suffit d'utiliser différents Identifiants sur
mNotificationManager.notify(ID, notifyDetails);
Si vous réutiliser le code, il ne sera pas en ajouter un nouveau, la place de la vieille seront mis à jour.
Ici est un guide sur la façon d'utiliser les notifications.
vous avez à chnage la notification id parce que c'est tout le temps pas la solution, c'est que vous devez utiliser aléatoire concept de nombre
Cet exemple montre comment créer de multiples Notification
Si vous souhaitez afficher des données différentes sur chaque notification. Utiliser le Drapeau
FLAG_UPDATE_CURRENT
dans l'attente de votreIntent
.Il met à jour les données sur chaque notification, sans avoir à le recréer à chaque fois.