Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Display a notification into the statusbar without an expandable view

I need help to do something. I try to display a notification into the android statusbar.

It will inform the user that a synchronization with the server is in progress.

Now, I use this code and it works fine :

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.stat_notify_sync).setWhen(System.currentTimeMillis())
            .setAutoCancel(false).setOngoing(true);

    NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notif = builder.getNotification();
    nm.notify(1, notif);

The only one problem is that a view is created when the user expand the statusbar. What I want to do is only display a small icon on the top of the status bar, without the contentview.

Anyone know how to do that ? Thanks in advance!

like image 249
nbe_42 Avatar asked Apr 09 '13 05:04

nbe_42


People also ask

How do I change the notification tray on my Android?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.

What is Android Statusbar?

Status bar (or notification bar) is an interface element at the top of the screen on Android devices that displays the notification icons, minimized notifications, battery information, device time, and other system status details.

How do I show status bar notifications?

By default, if you see a notification icon in the notification bar that you want to see more about, swipe down once from the top of your screen to expand your notifications.


Video Answer


1 Answers

This is not possible.

The rationale is this: if the user looks at the status bar and sees an icon, she should have some way of figuring out what that icon means. Therefore there must be a row in the notification panel corresponding to each icon.

I suggest creating a notification that explains, just as you have done in your question, that a synchronization is in progress; this is a great opportunity to indicate which app is currently syncing (so if there's some kind of problem or the sync is taking forever the user knows which app needs attention).

like image 123
dsandler Avatar answered Nov 14 '22 23:11

dsandler