Android – Mantenga la notificación estable en Notification Bar

He escrito la función para notificar y mostrar en la barra de notificación:

private void showNotification() { CharSequence title = "Hello"; CharSequence message = "Notification Demo"; NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon, "A Notification", System.currentTimeMillis()); Intent notificationIntent = new Intent(this, Main_Activity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(Main_Activity.this, title, message, pendingIntent); notificationManager.notify(NOTIFICATION_ID, notification); } 

Su funcionamiento muy bien, pero what way we can keep the notification steady at Notification bar incluso cuando el usuario presiona el botón "notificaciones claras" de la barra de notificación?

Por favor, eche un vistazo a la barra de notificación de la aplicación "Yahoo".

Introduzca aquí la descripción de la imagen

He ido a través de este artículo SDK: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating , pero no pudo averiguar.

Utilizar FLAG_NO_CLEAR

Sólo tiene que configurarlo en su instancia de Notification antes de suministrarlo al NotificationManager :

 notificaton.flags |= Notification.FLAG_NO_CLEAR; 

Editar: Acabo de notar que si usted está usando Notification.Builder (desde Honeycomb) y hacer la notificación "en curso", también será inmune a "borrar todo". Vea aquí .

Aparentemente, esto supone disuadir a los desarrolladores de usar FLAG_NO_CLEAR en un notificaton no en curso ya que esto podría confundir al usuario.

Intente setOngoing (true).

 notification = new Notification.Builder(getApplicationContext()) .setLargeIcon( BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setSmallIcon(R.drawable.ic_launcher).setTicker(tickerText) .setWhen(System.currentTimeMillis()).setContentTitle(contentTitle) .setOngoing(true) .setContentText(contentText) .setContentIntent(contentIntent) 
FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.