¿Cómo agregar el icono de la aplicación en la bandeja de notificación?
-
14-11-2019 - |
Pregunta
Entiendo que es posible.Al menos veo que varias aplicaciones utilizadas para poner en la bandeja de notificación sus iconos (por ejemplo, Skype).
¿Qué pasa con mi solicitud?¿Qué debo hacer para poner mi icono o mensaje en la barra de notificación?
Solución
You specify the UI information and actions for a notification in a
NotificationCompat.Builder
object. To create the notification itself, you callNotificationCompat.Builder.build()
, which returns aNotification
object containing your specifications. To issue the notification, you pass theNotification
object to the system by callingNotificationManager.notify()
...
Otros consejos
This is the code to put notification message in notification tray.100% working.
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this, EndActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// build notification
// the addAction re-use the same intent to keep the example short
Notification n = new Notification.Builder(this)
.setContentTitle("My message")
.setContentText("Subject")
.setSmallIcon(R.drawable.MyApplogo)
.setContentIntent(pIntent)
.setAutoCancel(true)
.setStyle(new Notification.BigTextStyle().bigText(""+msg.get(3))).build();
// .addAction(R.drawable.line, "", pIntent).build();
n.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, n);
Here is a great example to display the notification.