android 技术知识

Android 收起通知栏实现

2019-10-23  本文已影响0人  追梦小乐

1、实现代码

  public static void collapseStatusBar(Context context) {
        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 collapse = null;
            if (sdkVersion <= 16) {
                collapse = clazz.getMethod("collapse");
            } else {
                collapse = clazz.getMethod("collapsePanels");
            }
            collapse.setAccessible(true);
            collapse.invoke(service);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

2、权限

    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>

上一篇下一篇

猜你喜欢

热点阅读