samsung quitar que punto permitir pantalla ocultar notificación notificaciones las como cambiar burbujas bloqueo bloquear apps android notifications android-notifications android-5.0-lollipop

quitar - ocultar notificaciones android 9



¿Cómo suprimir la notificación en la pantalla de bloqueo en Android 5(Lollipop) pero dejarlo en el área de notificación? (4)

Después de actualizar a Android 5.0 Lollipop, comenzó a mostrar una notificación automática en curso en la pantalla de bloqueo.

A veces, los usuarios no quieren verlos a todos, por lo que les están preguntando a los desarrolladores cómo dejar la notificación en el área de estado, pero ocultarlos en la pantalla de bloqueo.

La única forma que encontré es obligar a los usuarios a usar el bloqueo de pantalla (por ejemplo, gestos o PIN) y establecer la setVisibility() programáticamente en VISIBILITY_SECRET . Pero no todos quieren usar el bloqueo de pantalla.

¿Hay alguna bandera (o combinación de banderas) que indique la notificación: no esté visible en la pantalla de bloqueo, pero sí en el área de notificación?


Utilizar visibilidad y prioridad.

Como se explica en esta respuesta , puede utilizar VISIBILITY_SECRET para suprimir la notificación en la pantalla de bloqueo cuando el usuario tiene un bloqueo de teclas seguro (no solo deslizar o no proteger) y se han eliminado las notificaciones confidenciales.

Para cubrir el resto de los casos, puede ocultar la notificación de la pantalla de bloqueo y la barra de estado programáticamente, estableciendo la prioridad de la notificación en PRIORITY_MIN siempre que esté presente el bloqueo del teclado y luego restablecer la prioridad cuando el protector del teclado esté ausente.

Desventajas

  • Al usar un emulador de Android 5, esto parece dar como resultado que la notificación aparezca muy brevemente en la pantalla de bloqueo pero luego desaparezca.
  • Ya no funciona a partir de Android O Developer Preview 2 cuando el usuario no tiene una pantalla de bloqueo segura (por ejemplo, solo deslizar) ya que las prioridades de notificación están en desuso .

Ejemplo

final BroadcastReceiver notificationUpdateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); .setVisibility(NotificationCompat.VISIBILITY_SECRET); KeyguardManager keyguardManager = (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE); if (keyguardManager.isKeyguardLocked()) builder.setPriority(NotificationCompat.PRIORITY_MIN); notificationManager.notify(YOUR_NOTIFICATION_ID, notification); } }; //For when the screen might have been locked context.registerReceiver(notificationUpdateReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); //Just in case the screen didn''t get a chance to finish turning off but still locked context.registerReceiver(notificationUpdateReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); //For when the user unlocks the device context.registerReceiver(notificationUpdateReceiver, new IntentFilter(Intent.ACTION_USER_PRESENT)); //For when the user changes users context.registerReceiver(notificationUpdateReceiver, new IntentFilter(Intent.ACTION_USER_BACKGROUND)); context.registerReceiver(notificationUpdateReceiver, new IntentFilter(Intent.ACTION_USER_FOREGROUND));


He creado un ''LockscreenIntentReceiver'' para mi notificación en curso que se ve así:


private class LockscreenIntentReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { String action = intent.getAction(); if (action.equals(Intent.ACTION_SCREEN_OFF)) { Log.d(TAG, "LockscreenIntentReceiver: ACTION_SCREEN_OFF"); disableNotification(); } else if (action.equals(Intent.ACTION_USER_PRESENT)){ Log.d(TAG, "LockscreenIntentReceiver: ACTION_USER_PRESENT"); // NOTE: Swipe unlocks don''t have an official Intent/API in android for detection yet, // and if we set ungoing control without a delay, it will get negated before it''s created // when pressing the lock/unlock button too fast consequently. Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (NotificationService.this.isNotificationAllowed()) { enableNotification((Context)NotificationService.this); } } }, 800); } } catch (Exception e) { Log.e(TAG, "LockscreenIntentReceiver exception: " + e.toString()); } } }

Básicamente, este código eliminará la notificación en curso cuando el usuario bloquee el teléfono (la eliminación será visible muy brevemente). Y una vez que el usuario desbloquee el teléfono, la notificación en curso se restaurará después del tiempo de demora (800 ms aquí). enableNotification () es un método que creará la notificación y llamará a startForeground () . Actualmente verificado para trabajar en Android 7.1.1.

Solo debe recordar registrarse y anular el registro del receptor.


Parece que VISIBILITY_SECRET hace el enfoque más limpio. Según la documentación:

se puede hacer una notificación VISIBILITY_SECRET, que suprimirá su icono y el ticker hasta que el usuario haya pasado por alto la pantalla de bloqueo.

Por la fuente (NotificationData en el proyecto SystemUI AOSP), VISIBILITY_SECRET es la única manera de hacerlo:

boolean shouldFilterOut(StatusBarNotification sbn) { if (!(mEnvironment.isDeviceProvisioned() || showNotificationEvenIfUnprovisioned(sbn))) { return true; } if (!mEnvironment.isNotificationForCurrentProfiles(sbn)) { return true; } if (sbn.getNotification().visibility == Notification.VISIBILITY_SECRET && mEnvironment.shouldHideSensitiveContents(sbn.getUserId())) { return true; } return false; }

El único otro tipo de notificaciones que parecen ser filtradas son las notificaciones secundarias en un grupo donde hay un resumen presente. Por lo tanto, a menos que tenga varios con un motivo válido para un resumen, VISIBILITY_SECRET es lo mejor que se puede hacer actualmente.


Puede establecer la prioridad de la notificación en PRIORITY_MIN . Esto debería ocultar la notificación en la pantalla de bloqueo. También oculta el ícono de la barra de estado (no estoy seguro de si lo desea), pero la notificación en sí sigue visible en el área de notificación.