• Home
  • Youzik
  • Papystreaming
  • Darknet
  • Libertyland
  • Cacaoweb
  • GG maps
  • Yggtorrent
  • Zone téléchargement

Grimag

  • Accueil
  • Catégories
    • Smartphone
    • High Tech
    • Business
    • Web
    • Appli Jeux Vidéo
    • Shopping
  • Android c’est quoi ?
  • Nous Contacter
  • Nos comparatifs
    • Drone avec caméra
    • Clavier d’ordinateur
    • Onduleur
    • GPS
    • Répéteur WiFi

Utiliser la bar de notification dans vos applications android



Dans ce tuto je vais mettre une alerte dans ma bar de modification quand je clique sur mon bouton
D’abord Mon fichier xml de mon interface.




    

Je crée deux objets de type NotificationManager(objet gérant les notifications) et Notification(objet de la notification)

 private NotificationManager mNotificationManager;
 Notification notification;

Ensuite j’instancie ces objets et avec la méthode setOnClickListener de mon bouton je lance une notification.

  super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //icone qui s'affichera dans la bar de notification
        int icon = R.drawable.icon;
       //texte dans la bar de notification
        CharSequence tickerText = "Notification android-france";
        long when = System.currentTimeMillis();

        notification = new Notification(icon, tickerText, when);
        
        Context context = getApplicationContext();
        CharSequence contentTitle = "Notification Android-france";
        CharSequence contentText = "Tuto Bar de notification";
        Intent notificationIntent = new Intent(this, Appnotif.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
      
        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
        
        Button btsauvegarde = (Button) findViewById(R.id.btn_showsample);
        btsauvegarde.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
            	mNotificationManager.notify(1,notification);
            }
        });

Résutat
notif1 notif3notif2

Sep 26, 2009Gnakouri Danon


Le HTC Tattoo à 379 euros sans abonnement chez The Phone HouseLe Acer A1 sous Android en pré-vente à 389 euros chez Expansys France
Gnakouri Danon

Co-fondateur du site Android france, senior lead developper, passionné de bière et de cigare cubain

26 septembre 2009 Developpement, Tuto développementandroid, Tutoriel129

2023 © Android-France