Skip to content

Instantly share code, notes, and snippets.

@XinyueZ
Last active May 30, 2023 10:41
Show Gist options
  • Save XinyueZ/7bad2c02be425b350b7f to your computer and use it in GitHub Desktop.
Save XinyueZ/7bad2c02be425b350b7f to your computer and use it in GitHub Desktop.
open close notification-bar
/*
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();
}
}
@asadaltaf583
Copy link

Not working in android 13

@asadaltaf583
Copy link

Getting this exception android.app.StatusBarManager.collapsePanels []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment