Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add application icon in notification tray?

I understand that it's possible. At least I see that various applications used to put in notification tray their icons (e.g. Skype).

What about my application? What should I do to put my icon or message in notification bar?

like image 309
Barmaley Avatar asked Feb 16 '11 19:02

Barmaley


People also ask

How do I add icons to my notification area?

Press and hold or right-click any empty space on the taskbar and select Taskbar settings. Under Taskbar corner icons: Select On for any icons you want to see on the taskbar.


2 Answers

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()...

like image 180
Thomas Avatar answered Oct 15 '22 07:10

Thomas


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); 
like image 29
Pir Fahim Shah Avatar answered Oct 15 '22 06:10

Pir Fahim Shah