Cómo ocultar el Panel de notificaciones después de enviar un PendingIntent al servicio en una notificación
Todos
Escribo un servicio para actualizar el estado del sistema, y uso startForeground para poner el servicio en primer plano, y también le agrego una notificación. En la notificación, utilizo remoteView para tener tres imágenes con tres OnClickPendingIntent. Uno de ellos está enviando de vuelta al servicio y realiza los códigos de actualización de notificaciones.
código para crear la notificación:
Intent intentApp = new Intent(this,ScreenOffWidgetConfigure.class);
intentApp.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent piApp = PendingIntent.getActivity(this, 0, intentApp, 0);
Intent intentOnOff = new Intent(CV.SERVICE_INTENT_ACTION);
intentOnOff.putExtra(CV.SERVICEACTION, CV.SERVICEACTION_TOGGLE);
PendingIntent piOnOff = PendingIntent.getService(this, 0, intentOnOff, 0);
Intent intentScreenOff = new Intent(CV.SERVICE_INTENT_ACTION);
intentScreenOff.putExtra(CV.SERVICEACTION, CV.SERVICEACTION_SCREENOFF);
PendingIntent piScreenOff = PendingIntent.getService(this, 1, intentScreenOff, 0);
// setup remoteview
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.layout_notification);
remoteViews.setOnClickPendingIntent(R.id.image_logo, piApp);
remoteViews.setOnClickPendingIntent(R.id.image_status, piOnOff);
remoteViews.setOnClickPendingIntent(R.id.image_screenoff, piScreenOff);
if(CV.getPrefChargingOn(this) && CV.isPlugged(this))
{
remoteViews.setImageViewResource(R.id.image_status,R.drawable.widget_charging_on);
}
else
{
if(CV.getPrefAutoOnoff(this))
remoteViews.setImageViewResource(R.id.image_status,R.drawable.widget_on);
else
remoteViews.setImageViewResource(R.id.image_status,R.drawable.widget_off);
}
// build the notification
Notification noti = new Notification.Builder(this)
.setContent(remoteViews)
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.build();
return noti;
Código para la notificación de actualización, después de recibir la intención:
Notification notify = createNotification();
final NotificationManager notificationManager = (NotificationManager) getApplicationContext()
.getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ONGOING, notify);
Mi pregunta es: después de llamar a mi función de actualización, la imagen de notificación realmente se cambia; sin embargo,El panel de notificaciones sigue ahí !! No desaparece como lo que debería ser para lanzar actividades.
¿Hay algún indicador que pueda establecer para la notificación, el Intento pendiente o qué llamadas a la API puedo usar después de recibir la intención en servicio?