1. 添加权限
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
2. 通过反射调用 android.app.StatusBarManager 中的 collapse(Build.VERSION.SDK_INT <= 16) 或 collapsePanels(Build.VERSION.SDK_INT > 16) 方法。
public static void collapseStatusBar(Context context) {
try {
Object statusBarManager = context.getSystemService("statusbar");
Method collapse; if (Build.VERSION.SDK_INT <= 16) {
collapse = statusBarManager.getClass().getMethod("collapse");
} else {
collapse = statusBarManager.getClass().getMethod("collapsePanels");
}
collapse.invoke(statusBarManager);
} catch (Exception localException) {
localException.printStackTrace();
}
}