Android: Iniciar primer plano no mostrará la notificación correctamente
Estoy trabajando en una aplicación que utiliza un servicio en primer plano. para esto llamostartForeground(id,Notification)
desde adentro onStartCommand devolución de llamada del servicio.
Utilizo un generador de notificaciones para crear mi notificación, pero cuando la paso al inicio Solo aparece el texto del teletipo cuando lo configuro, todo lo demás se convierte en predeterminado, es decir, el Título dice "se está ejecutando mientras lo tenía configurado como" está en línea "
También todo lo que había configurado usando el método setText y setInfo en la notificación. El generador no aparece en su lugar el texto predeterminado como "toque para obtener más información o para detener la aplicación" en su lugar.
Aquí está el código relevante:
Servicio :
private final int NOTIFICATION_ID=1;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this,"EDI: Core service Started" , Toast.LENGTH_LONG).show();
startForeground(NOTIFICATION_ID, CoreServiceNotification.getNotification(this, "EDI is online", "Online","Online and running","EDI just started"));
return super.onStartCommand(intent, flags, startId);
}
CoreServiceNotification:
public class CoreServiceNotification {
public static Notification getNotification(Context context,String title,String text,String info,String tickerText){
Notification.Builder notificationBuilder= new Notification.Builder(context);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(text);
notificationBuilder.setContentInfo(info);
notificationBuilder.setTicker(tickerText);
notificationBuilder.setLights(0x00ffff00, 1000, 0);
return notificationBuilder.build();
}
}
RESULTADO: