Android 4.2 禁止下拉状态栏

最近在做一个界面需要禁止下拉状态栏,于是整理了一下,以后备用。

import android.app.StatusBarManager;//首先导入包


StatusBarManager mStatusBar = (StatusBarManager) getSystemService(this.STATUS_BAR_SERVICE);//获得对象
mStatusBar.disable(StatusBarManager.DISABLE_EXPAND);//禁止下拉状态栏


mStatusBar.disable(StatusBarManager.DISABLE_NONE);//启用下拉状态栏(在onDestroy()添加)


//此代码只能在源码环境下才能编译


---------------------------------------------------源码中是这样定义的--------------------------------------------------------

source/frameworks/base/core/java/android/app/StatusBarManager.java

public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;

public static final int DISABLE_NONE = 0x00000000;


/**
     * Disable some features in the status bar.  Pass the bitwise-or of the DISABLE_* flags.
     * To re-enable everything, pass {@link #DISABLE_NONE}.
     */
    public void disable(int what) {
        try {
            final IStatusBarService svc = getService();//获得IStatusBarService 的对象
            if (svc != null) {
                svc.disable(what, mToken, mContext.getPackageName());
//实际上使用的是IStatusBarService的disable方法
            }
        } catch (RemoteException ex) {
            // system process is dead anyway.
            throw new RuntimeException(ex);
        }
    }


private synchronized IStatusBarService getService() {
        if (mService == null) {
            mService = IStatusBarService.Stub.asInterface(
                    ServiceManager.getService(Context.STATUS_BAR_SERVICE));
//使AIDL获取IStatusBarService对象
            if (mService == null) {
                Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
            }
        }
        return mService;
    }


source/frameworks/base/services/java/com/android/server/StatusBarManagerService.java

    public void disable(int what, IBinder token, String pkg) {
        disableInternal(mCurrentUserId, what, token, pkg);
    }


    private void disableInternal(int userId, int what, IBinder token, String pkg) {
        enforceStatusBar();

        synchronized (mLock) {
            disableLocked(userId, what, token, pkg);
        }
    }


   private void disableLocked(int userId, int what, IBinder token, String pkg) {
        // It's important that the the callback and the call to mBar get done
        // in the same order when multiple threads are calling this function
        // so they are paired correctly.  The messages on the handler will be
        // handled in the order they were enqueued, but will be outside the lock.
        manageDisableListLocked(userId, what, token, pkg);
        final int net = gatherDisableActionsLocked(userId);
        if (net != mDisabled) {
            mDisabled = net;
            mHandler.post(new Runnable() {
                    public void run() {
                        mNotificationCallbacks.onSetDisabled(net);
                    }
                });
            if (mBar != null) {
                try {
                    mBar.disable(net);
                } catch (RemoteException ex) {
                }
            }
        }
    }

source/frameworks/base/core/java/android/view/View.java

    /**
     * @hide
     *
     * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
     * out of the public fields to keep the undefined bits out of the developer's way.
     *
     * Flag to make the status bar not expandable.  Unless you also
     * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show.
     */
    public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000;





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值