简体   繁体   中英

Android Notification Icon

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.

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);

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM