开发者

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

        }


Notification Manager.

Example here


have you had a look at LevelListDrawable?

http://developer.android.com/reference/android/graphics/drawable/LevelListDrawable.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜