0

My application should run in full screen mode. And also i have to show notification bar when new items arrived to my app from our server. I write coding for notification in BroadcastReceiver class. i would like to make a decision in MainActivity like show the status bar only when new notification received otherwise hide the status bar. All are done when app is in foreground.

Coding for Notification:

Intent scheduledIntent = new Intent(context,Activity.class);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, scheduledIntent, 0);

                nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                CharSequence from = "From address";
                CharSequence message = "New Orders received";
                Notification notif = new Notification(R.drawable.icon,"Hai", System.currentTimeMillis());
                notif.setLatestEventInfo(context, from, message, pendingIntent);
                notif.flags |= Notification.FLAG_AUTO_CANCEL;
                nm.notify(uniqueID, notif);
                notif.ledOnMS = 500;
                notif.ledOffMS = 500;

Through this code notifications are recieved. But the status bar is always visible. I need to hide when no notification received. Please provide me the right way to do this.

Thanks in advance,

Sridhar
  • 2,228
  • 10
  • 48
  • 79

1 Answers1

0

In OnCreate() method you have to write this one:

 AppPreferences prefs = new AppPreferences(PresentChatActivity.this);
             boolean notify_checkbox = prefs.getNotifyState();

    Notification(message.getBody(),fromName, name);

Then, outside OnCreate(), write this function

   protected void Notification(String body, String fromName, String Notificationmsg) {

    NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);      

    String tickerText = getString(R.string.app_name, body);
    Notification notif = new Notification(R.drawable.ic_launcher, tickerText,
            System.currentTimeMillis());

    Intent notificationIntent = new Intent(this, PresentChatActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);


     notif.setLatestEventInfo(PresentChatActivity.this,Notificationmsg, message, pendingIntent);
     notif.setLatestEventInfo(getApplicationContext(), fromName, body,pendingIntent );  
     notificationManager.notify(10001, notif);
     }
B. León
  • 529
  • 7
  • 12
shassss
  • 321
  • 1
  • 13
  • what is notify_checkbox and chat_data – Sridhar Sep 07 '12 at 04:32
  • its nothing but we notification check box then ckeck box have check only the notification wil dispaly,otherwise notification wont display – shassss Sep 07 '12 at 04:33
  • in ur progrmm no need to check and unchecked means u can add directly like this Notification(message.getBody(),fromName, name); – shassss Sep 07 '12 at 04:34
  • cant understand your logic. i dont have any checkbox in my app, the thing is show/hide status bar – Sridhar Sep 07 '12 at 04:37
  • ho kkk just simply u want to display notoficationaaa??tel me this clearly – shassss Sep 07 '12 at 04:38
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16398/discussion-between-sridhar-and-shassss) – Sridhar Sep 07 '12 at 04:44
  • Ok good, but i need to show/hide the status bar, you can see my code for creating notification, it was working good and status bar is always visible. – Sridhar Sep 07 '12 at 05:00
  • I need to hide the status bar if no notification received – Sridhar Sep 07 '12 at 05:01
  • i need like some NotificationManager for detecting new notification received – Sridhar Sep 07 '12 at 05:02
  • write this in ur code to hide status bar @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); } – shassss Sep 07 '12 at 05:11
  • ok, so notify_checkbox will true when new notification received right – Sridhar Sep 07 '12 at 05:13
  • I write code for Notification in BroadcastReceiver class onReceive() method ok. shall i write in onCreate(){ AppPreferences prefs = new AppPreferences(PresentChatActivity.this); boolean notify_checkbox = prefs.getNotifyState(); – Sridhar Sep 07 '12 at 05:19
  • AppPreferences is in which package. i am using android 4.03 – Sridhar Sep 07 '12 at 05:26
  • u have to create new pakageeee for dat...nd iam using 2.2 – shassss Sep 07 '12 at 05:27
  • My team lead, ask me to drop notification functionality – Sridhar Sep 07 '12 at 06:01