private void hideNoticBar()
{
@SuppressLint("WrongConstant")
Object service = getSystemService("statusbar");
if (null == service)
{
Log.d(TAG, "hide null");
return;
}
try
{
Class<?> clazz = Class.forName("android.app.StatusBarManager");
int sdkVersion = android.os.Build.VERSION.SDK_INT;
Method collapse = null;
if (sdkVersion <= 16)
{
collapse = clazz.getMethod("collapse");
}
else
{
collapse = clazz.getMethod("collapsePanels");
}
collapse.setAccessible(true);
collapse.invoke(service);
Log.d(TAG, "hide collapse ");
}
catch (Exception e)
{
Log.d(TAG, "hide Exception " + e.getCause());
e.printStackTrace();
}
}
public void expandNotification(Context context)
{
@SuppressLint("WrongConstant")
Object service = context.getSystemService("statusbar");
if (null == service)
{
return;
}
try
{
Class<?> clazz = Class.forName("android.app.StatusBarManager");
int sdkVersion = android.os.Build.VERSION.SDK_INT;
Method expand = null;
if (sdkVersion <= 16)
{
expand = clazz.getMethod("expand");
}
else
{
expand = clazz.getMethod("expandSettingsPanel");
}
expand.setAccessible(true);
expand.invoke(service);
Log.d(TAG, "hide expandSettingsPanel ");
}
catch (Exception e)
{
e.printStackTrace();
}
}
添加权限
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>