How to determine the status bar extension?

My application allows me to run another application with me. None of my actions show a status bar. But when you start other applications, such as Camera, the user can access status bar. So I tried the following code snippet to collapse status barinside the service (so it collapses every time, and the code always works).

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 baronly if the user tries to expand this.Is exist intentor intent filterto detect the extension status bar?

Thanks at Advance

+5
source share
2 answers

There is no callback if the notification bar is dragged onto Android.

, Android , , , .

+4

onWindowFocusChanged() .

<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();
        }
    }
}
+8

All Articles