Los botones de notificación de Android no aparecen
Este es mi código para configurar una notificación con botones.
Intent receiverIntent = new Intent(ctx, ResponsivePrefsActivity.class); PendingIntent pReceiverIntent = PendingIntent.getActivity(ctx, 1, receiverIntent, 0); Intent clearIntent = new Intent(ctx, ResponsivePrefsActivity.class); clearIntent.setAction("clear"); PendingIntent pClearIntent = PendingIntent.getActivity(ctx, 1, clearIntent, 0); Intent colorsIntent = new Intent(ctx, ResponsivePrefsActivity.class); colorsIntent.setAction("colors"); PendingIntent pColorsIntent = PendingIntent.getActivity(ctx, 1, colorsIntent, 0); Intent animationIntent = new Intent(ctx, ResponsivePrefsActivity.class); animationIntent.setAction("animation"); PendingIntent pAnimation = PendingIntent.getActivity(ctx, 1, animationIntent, 0); Notification.Builder builder; builder = new Notification.Builder(ctx).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false) .setContentTitle("Draw Me: A Live Wallpaper").setContentText("Never get bored again!") .setContentIntent(pReceiverIntent).addAction(R.raw.ic_menu_close_clear_cancel, "Clear", pClearIntent) .addAction(R.raw.ic_menu_edit, "Colors", pColorsIntent).addAction(R.raw.ic_menu_play_clip, "Animation", pAnimation); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification);
La notificación está apareciendo pero los botones no. Mi dispositivo tiene Android 4.1.1 Establece esta notificación en un fragmento. ¿Qué estoy haciendo mal? ¡Gracias!
- Color de fondo de notificación predeterminado
- ¿Cómo hacer que la función de notificación de respuesta directa de Android funcione en dispositivos pre-Android N?
- Notificación de la pantalla de bloqueo de Android Facebook
- Android PendingIntent te lleva a una actividad ya existente?
- Apertura del navegador en la notificación push
- ¿Cómo mostrar la notificación múltiple como un grupo?
- ¿Es posible configurar la notificación ampliada como predeterminada en las notificaciones de texto grande?
- Visualización de emojis en el contenido de la notificación
- RemoteView no muestra botones en la notificación personalizada
- ¿Cómo iniciar la actividad cuando el usuario hace clic en una notificación?
- Android Cómo abrir la última actividad al hacer tapping en la notificación
- Android: actualización de la barra de progreso de la notificación, correctamente
- Cómo crear una notificación con NotificationCompat.Builder?
Déjeme decirle algo que es realmente incómodo. Si tiene algo en su notificación en curso, no verá los botones. Normalmente sucede cuando el teléfono está conectado al PC vía USB. Espero que esto resuelva tu problema
Sólo un recordatorio para cualquier persona con un problema similar. Según la Guía de notificaciones de Android, las notificaciones pueden aparecer en dos estilos:
- Normal View, donde los botones de acción no aparecen de forma predeterminada (y el usuario tiene que expandir la notificación, para que aparezcan)
- Vista grande, que es visible si la notificación es la primera en la lista de notificaciones o el usuario ha expandido la notificación.
Por lo tanto, para obligar a la notificación a aparecer en Big View, todo lo que tenemos que hacer es simplemente colocarlo en la parte superior de la lista de notificaciones. Esto se puede hacer estableciendo la propiedad When en 0, que la convierte en la más antigua entre las notificaciones. (A veces aunque no queramos esto). Entonces llama
setWhen(0)
A su notificación y ya está.
Los botones no aparecerán cuando haya ninguna notificación en curso presente en la lista, como un control de reproductor multimedia o las opciones de conmutador IME cuando esté editando texto.
Afortunadamente, esto se puede superar simplemente fijando la prioridad de la notificación agradable y alta. Sólo he usado Notification.PRIORITY_MAX para evitar esto, pero PRIORITY_HIGH parece funcionar también. Establecer como este:
Notification notification = new Notification.Builder(myContext) .setContentTitle(res.getString(R.string.my_title)) .setPriority(Notification.PRIORITY_MAX) //The rest of your options .build();
Solo haz esto
.setPriority(Notification.PRIORITY_MAX) .setWhen(0)
El código completo es:
Notification noti = new Notification.Builder(this) .setContentTitle("New mail from " + "[email protected]") .setContentText("Subject").setSmallIcon(R.drawable.ic_launcher) .setContentIntent(pIntent) .setPriority(Notification.PRIORITY_MAX) .setWhen(0) .addAction(R.drawable.ic_launcher, "Call", pIntent) .addAction(R.drawable.ic_launcher, "More", pIntent) .addAction(R.drawable.ic_launcher, "And more", pIntent).build();
Sólo haz algunos cambios como este en tu code
Notification n = new Notification.Builder(this) .setSmallIcon(R.drawable.icon) .setContentTitle("New mail from " + "[email protected]") .setContentText("Subject") .setContentIntent(pIntent).setAutoCancel(true) .setStyle(new Notification.BigTextStyle().bigText(longText)) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Hide the notification after its selected notificationManager.notify(0, n);
Añade lo que necesitas en esta .. Espero que te ayude ..
- Resaltando el elemento seleccionado en el listview en android
- MediaCodec y Camera: los colores no coinciden