Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to collapse status bar on android 4.2? [duplicate]

Is there a way to collapse notification bar on Android 4.2?

I use this code that works only for the previous Android versions:

try{
            Object service  = c.getSystemService("statusbar");
            Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
            Method collapse = statusbarManager.getMethod("collapse");
            collapse.setAccessible(true);
            collapse.invoke(service);
        }catch(Exception ex){}

Please help me...

like image 804
Meroelyth Avatar asked Dec 07 '12 16:12

Meroelyth


1 Answers

It's hacky but since you have decided to tread that path, try to use the following code.

        if (currentApiVersion <= 16) {
            Method collapse = statusbarManager.getMethod("collapse");
            collapse.invoke(service);
        } else {
            Method collapse2 = statusbarManager.getMethod("collapsePanels");
            collapse2.invoke(service);
        }
like image 75
Nitin Sethi Avatar answered Sep 28 '22 02:09

Nitin Sethi