Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect expanding of status bar?

My application allows launching of other application from mine. None of my activity shows Status Bar.But when launching other applications like Camera the user can access the status bar.So i tried the following code snippet for collapsing the Status Bar inside a service(So it collapse every time and code running always).

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method collapse = null;
if(currentapiVersion <= 16){
    collapse = statusbarManager.getMethod("collapse");
}else{
    collapse = statusbarManager.getMethod("collapsePanels");
}
collapse.setAccessible(true);
collapse.invoke(service);

Now i want to collapse status bar only if user try to expand this.Is there any intent or intent filter exist for detect expanding of Status bar?

Thanks in Advance

like image 645
Devu Soman Avatar asked Apr 30 '13 10:04

Devu Soman


People also ask

What is the size of status bar?

Official height is 24dp , as is stated officially by Google on Android Design webpage. Save this answer.

What is a status bar notification?

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.

Does the status bar have shortcuts?

To add an app shortcut, touch the plus button in the lower-right corner of the screen. Scroll through the list of apps and touch an app you want to add to the notification bar. Once you select an app, it's added to the main Bar Launcher screen.


2 Answers

There is no callback of any kind when the notification bar is dragged down on Android.

This is because Android apps are meant to be designed in a way that the notification bar coming up and going away does not affect the functioning in any way.

like image 191
Raghav Sood Avatar answered Nov 25 '22 02:11

Raghav Sood


In your activity override the onWindowFocusChanged() method and write the below code.

This uses the following permission:

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

@Override
public void onWindowFocusChanged(boolean hasFocus)
{
    try
    {
        if(!hasFocus)
        {
            Object service  = getSystemService("statusbar");
            Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
            Method collapse = statusbarManager.getMethod("collapse");
            collapse .setAccessible(true);
            collapse .invoke(service);
        }
    }
    catch(Exception ex)
    {
        if(!hasFocus)
        {
            try {
                Object service  = getSystemService("statusbar");
                Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
                Method collapse = statusbarManager.getMethod("collapse");
                collapse .setAccessible(true);
                collapse .invoke(service);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();                
            }
            ex.printStackTrace();
        }
    }
}
like image 36
Lalith B Avatar answered Nov 25 '22 02:11

Lalith B