overview notification ejemplo custom anatomy android notifications

notification - Android: ¿Cómo crear una notificación "en curso"?



notification overview android (4)

Hola, ¿cómo creo la notificación permanente como la primera para el indicador de batería?


En caso de que esté utilizando NotificationCompat.Builder , puede usar:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) mBuilder.setOngoing(true); //this will make ongoing notification


En realidad, se recomienda a nivel de bit, o indicadores de notificación, en lugar de establecer los indicadores directamente. Esto le permite establecer múltiples banderas a la vez.

Por ejemplo:

notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_SHOW_LIGHTS;

establecerá ambas banderas a la vez, mientras que:

notification.flags = Notification.FLAG_ONGOING_EVENT; notification.flags = Notification.FLAG_SHOW_LIGHTS;

solo configurará el indicador FLAG_SHOW_LIGHTS.


Asigne el indicador Notification.FLAG_ONGOING_EVENT a su Notification .

Código de muestra:

yourNotification.flags = Notification.FLAG_ONGOING_EVENT; // Notify...

Si no está familiarizado con la API de Notification , lea Crear notificaciones de la barra de estado en el sitio web de desarrolladores de Android.


public static final int FLAG_ONGOING_EVENT

Desde: Nivel de API 1
El bit que se debe asignar a bits en el campo de banderas se debe establecer si esta notificación hace referencia a algo que está en curso, como una llamada telefónica.

public static final int FLAG_FOREGROUND_SERVICE

Dado que: Nivel 5 de la API Nivel de bit a nivel de bits en el campo de banderas que se debe establecer si esta notificación representa un servicio que se está ejecutando actualmente.