Search code examples
androidnotificationsstatusbar

Android show notification only when the status bar is expanded


Is it possible in Android to show notification only when the status bar is expanded? I mean only when I dragged down the status bar, I can see the notification otherwise it will be hidden. If it is possible how I can implement it? I just need to hide the application icon from status bar when it is in the minimal view.Check this


Solution

  • Actually I figured it out myself that from Android 4.1 (API 16) it's possible to specify a notification's priority. If you set that flag to PRIORITY_MIN the notification icon won't show up on the statusbar but you are still able to view the notification on expanding the statusbar.

    // Use NotificationCompat.Builder to set up our notification.
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
                this).setOngoing(true);
        notificationBuilder.setContentTitle("my_title"); 
        notificationBuilder.setSmallIcon(ic_launcher);
    // Do other stuffs here.
    
     notificationBuilder.setPriority(Notification.PRIORITY_MIN);// Set this.