Last active
August 29, 2015 14:19
-
-
Save ziedrebhi/ab04c8c10b2dcc3ef6b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final void ajouterNotification() { | |
// Récupération du notification Manager | |
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
// Récupération du titre et description de la notification | |
final String notificationTitle = "Ma notification"; | |
final String notificationDesc = "Cliquez ici , je suis une notification"; | |
// Création de la notification avec spécification de l'icône de la | |
// notification et le texte qui apparait à la création de la | |
// notification | |
final Notification notification = new Notification( | |
R.drawable.ic_launcher, notificationTitle, | |
System.currentTimeMillis()); | |
// Définition de la redirection au moment du clic sur la notification. | |
// Dans notre cas la notification redirige vers notre application : MainActivity | |
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, | |
new Intent(this, MainActivity.class), 0); | |
// Notification avec Vibration | |
notification.setLatestEventInfo(this, notificationTitle, | |
notificationDesc, pendingIntent); | |
notification.vibrate = new long[] { 0, 200, 100, 200, 100, 200 }; | |
notificationManager.notify(NOTIFICATION_ID, notification); | |
} | |
private void supprimerNotification() { | |
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
// On supprime la notification grâce à son ID : NOTIFICATION_ID | |
notificationManager.cancel(NOTIFICATION_ID); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment