Skip to content

Instantly share code, notes, and snippets.

@ziedrebhi
Last active August 29, 2015 14:19
Show Gist options
  • Save ziedrebhi/ab04c8c10b2dcc3ef6b4 to your computer and use it in GitHub Desktop.
Save ziedrebhi/ab04c8c10b2dcc3ef6b4 to your computer and use it in GitHub Desktop.
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