No se puede encontrar el símbolo NOTIFICATION_SERVICE?
package com.test.app; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class runOnBoot extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); } }
Cuando intento construir el paquete, dice
compile: [javac] Compiling 2 source files to /home/mrburns/Desktop/myapp/bin/classes [javac] /home/mrburns/Desktop/myapp/src/com/test/app/runOnBoot.java:14: cannot find symbol [javac] symbol : variable NOTIFICATION_SERVICE [javac] location: class runOnBoot [javac] NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); [javac] ^ [javac] 1 error BUILD FAILED
- En Android, ¿cómo puedo saber el ID de notificación actual para borrar la notificación
- ¿Cómo borrar correctamente toda la notificación una vez hecho clic?
- La lista de animación se reiniciará cuando actualice notificaciones (NotificationManager.notify) en Lollipop
- Múltiples notificaciones para la misma actividad
- Android Remoteviews para notificaciones ampliadas
- ¿Cómo usar la notificación con sonido y vibración?
- NotificationManager obtener notificación por Id
- Notificación de cancelación automática no funciona para Android Lollipop
- ¿Cómo establecer el detector de clics para la notificación?
- Cómo implementar el servicio de notificación (no utilizar la actividad) en android
- GCM push notificación. Notificación incorrecta publicada - No se pudo expandir RemoteViews para: StatusBarNotification
- ¿Cómo detectar si se ha rechazado una notificación?
- Cómo crear un icono de barra de estado en el lado derecho? (Androide)
He encontrado que llamar de esta manera funciona:
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Esto debe ser Context.NOTIFICATION_SERVICE
:
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager mNotifyMgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Deberías intentarlo mejor
NotificationManager nm = (NotificationManager)getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
- Android WebView lanza "peticiones de origen cruzado sólo son compatibles con http" excepción al intentar cargar recursos desde el disco
- Cómo cambiar el diseño del widget de fondo mediante programación