Last active
May 30, 2023 10:41
-
-
Save XinyueZ/7bad2c02be425b350b7f to your computer and use it in GitHub Desktop.
open close notification-bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For opening and closing the notification-bar programmatically. Here is an example for closing. | |
<uses-permission android:name=“android.permission.EXPAND_STATUS_BAR” /> | |
It might be an unofficial info. | |
http://stackoverflow.com/questions/5029354/how-can-i-programmatically-open-close-notifications-in-android http://stackoverflow.com/questions/13766789/android-how-to-collapse-status-bar-on-android-4-2 | |
*/ | |
private static void collpasePanel(Context _context) { | |
try { | |
Object sbservice = _context.getSystemService("statusbar"); | |
Class<?> statusbarManager; | |
statusbarManager = Class.forName("android.app.StatusBarManager"); | |
Method showsb; | |
if (Build.VERSION.SDK_INT >= 17) { | |
showsb = statusbarManager.getMethod("collapsePanels"); | |
} else { | |
showsb = statusbarManager.getMethod("collapse"); | |
} | |
showsb.invoke(sbservice); | |
} catch (ClassNotFoundException _e) { | |
_e.printStackTrace(); | |
} catch (NoSuchMethodException _e) { | |
_e.printStackTrace(); | |
} catch (IllegalArgumentException _e) { | |
_e.printStackTrace(); | |
} catch (IllegalAccessException _e) { | |
_e.printStackTrace(); | |
} catch (InvocationTargetException _e) { | |
_e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting this exception android.app.StatusBarManager.collapsePanels []