Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Notification Icon

Tags:

android

New to Android development. I'm wondering if its possible to programmatically draw an icon to put in the notification bar? What if we want the icon to display some dynamic text for something like battery level?

If anyone has a code sample it would be nice. Thanks.

like image 996
Someone Else Avatar asked Nov 05 '10 01:11

Someone Else


2 Answers

Call the function where we want notification.

 public void notification(String name) {

            final int id = 2;
            String ns = Context.NOTIFICATION_SERVICE;
            NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
            int icon = R.drawable.fbc;
            CharSequence tickerText = "facebook";
            long when = System.currentTimeMillis();

            Notification checkin_notification = new Notification(icon, tickerText,
                    when);
            Context context = getApplicationContext();
            CharSequence contentTitle = "You are name is"+ name;
            CharSequence contentText = "Do You want to Check-in ?? ";

                Intent notificationIntent = new Intent(context, LoginTab.class);
                PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                        notificationIntent, 0);
                checkin_notification.setLatestEventInfo(context, contentTitle,
                        contentText, contentIntent);
                checkin_notification.flags = Notification.FLAG_AUTO_CANCEL;
                notificationManager.notify(id, checkin_notification);

        }
like image 70
anoop Avatar answered Sep 18 '22 11:09

anoop


Notification Manager.

Example here

like image 31
xandy Avatar answered Sep 16 '22 11:09

xandy