开发者

How to set text on status bar notification in Android

开发者 https://www.devze.com 2023-03-11 16:51 出处:网络
How can i set text to t开发者_开发技巧he top notification bar in android Ex: hello worldString ns = Context.NOTIFICATION_SERVICE;

How can i set text to t开发者_开发技巧he top notification bar in android Ex: hello world


                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
                int icon = R.drawable.icon;    
                CharSequence tickerText = "Notification Receive";
                long when = System.currentTimeMillis();

                Notification notification = new Notification(icon, tickerText, when);

                Context context1 = context;
                //*****************
                final int CUSTOM_VIEW_ID = 1;
                RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
                contentView.setImageViewResource(R.id.image, R.drawable.icon);
                contentView.setTextViewText(R.id.text, "Racquetime \n"+msg);

                notification.contentView = contentView;


              notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
              Intent notificationIntent;
              if(GUIStatics.boolLoginStatus)
              {
                  notificationIntent = new Intent(this,ShowAllNotificationActiviry.class);
              }
              else{
                   notificationIntent = new Intent(this, HomeActivity.class);
              }
              notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notification.defaults |= Notification.DEFAULT_SOUND;
                notification.flags |= Notification.FLAG_SHOW_LIGHTS;

                notificationIntent.putExtra("Tag", "C2DMBaseReceiver");
                PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
                notification.contentIntent = contentIntent;
                mNotificationManager.notify(CUSTOM_VIEW_ID, notification);

I am using this code for showing notification on notification bar you can change it according to your requirement. I hope this is help.

0

精彩评论

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