Pour plus d'informations consultez ce Link.
autorisation Ajouter à votre fichier manifeste
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
EDIT // 1. Procurez-vous une référence au NotificationManager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
// 2. Instantiate la notification
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
// 3. Définir e message étendu de la notification et l'intention
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
// 4. Passer la notification au NotificationManager
private static final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
// ----------------- ----- // Ajouter un son // ---------------------- // a. Son par défaut
notification.defaults |= Notification.DEFAULT_SOUND;
// b. son sur mesure à partir de la carte SD
notification.sound = Uri.parse("file:///sdcard/notification/SOUND.mp3");
// // ---------------------- Ajouter Vibration // ------ ---------------- // a. Vibration par défaut
notification.defaults |= Notification.DEFAULT_VIBRATE;
// b. vibrations sur mesure
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
// // ------------------------ Ajouter Flashing Lights // ------ ------------------ // a. Feux par défaut
notification.defaults |= Notification.DEFAULT_LIGHTS;
// b. lumières personnalisées
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;