可用于点击Notifacation之后收起状态栏
public static final void collapseStatusBar(Context ctx) {
Object sbservice = ctx.getSystemService("statusbar");
try {
Class> statusBarManager = Class.forName("android.app.StatusBarManager");
Method collapse;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
collapse = statusBarManager.getMethod("collapsePanels");
} else {
collapse = statusBarManager.getMethod("collapse");
}
collapse.invoke(sbservice);
} catch (Exception e) {
e.printStackTrace();
}
}
public static final void expandStatusBar(Context ctx) {
Object sbservice = ctx.getSystemService("statusbar");
try {
Class> statusBarManager = Class.forName("android.app.StatusBarManager");
Method expand;
if (Build.VERSION.SDK_INT >= 17) {
expand = statusBarManager.getMethod("expandNotificationsPanel");
} else {
expand = statusBarManager.getMethod("expand");
}
expand.invoke(sbservice);
} catch (Exception e) {
e.printStackTrace();
}
}