Как добавить значок приложения в лоток уведомления?

StackOverflow https://stackoverflow.com/questions/5021418

  •  14-11-2019
  •  | 
  •  

Вопрос

Я понимаю, что это возможно.По крайней мере, я вижу, что различные приложения, используемые для поставок в лоток для уведомления, их значки (например, Skype).

Как насчет моего приложения?Что я должен сделать, чтобы поставить свою икону или сообщение в баре уведомлений?

Это было полезно?

Решение

Documentation.

You specify the UI information and actions for a notification in a NotificationCompat.Builder object. To create the notification itself, you call NotificationCompat.Builder.build(), which returns a Notification object containing your specifications. To issue the notification, you pass the Notification object to the system by calling NotificationManager.notify()...

Другие советы

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.

Notification Demo

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top