Android7.1 动态显示和隐藏导航栏和状态栏 广播

由于公司项目需要动态显示和隐藏导航栏和状态栏,所以就需要从底层代码加入广播命令,下面是实际操作过程。


一、文件路径	
       /frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
	   在源码中增加如下代码,保存后重新编译,然后用adb shell am -a "..........."命令测试,
	   例如:adb shell am -a "lyzk.intent.systemui.hidenavigation"
private int mNavigationIconHints = 0;
    private HandlerThread mHandlerThread;

    //Add By LYZK 2021/6/29
    private static final String SHOW_NAVIGATION = "lyzk.intent.systemui.shownavigation";
    private static final String HIDE_NAVIGATION = "lyzk.intent.systemui.hidenavigation";
    private static final String SHOW_STATUSBAR = "lyzk.intent.systemui.showstatusbar";
    private static final String HIDE_STATUSBAR = "lyzk.intent.systemui.hidestatusbar";
    //End Add

    // ensure quick settings is disabled until the current user makes it through the setup wizard
    private boolean mUserSetup = false;
demoFilter.addAction(ACTION_DEMO);
        context.registerReceiverAsUser(mDemoReceiver, UserHandle.ALL, demoFilter,
                android.Manifest.permission.DUMP, null);

        //Add By LYZK 2021/6/29
        IntentFilter carfilter = new IntentFilter();
        carfilter.addAction(SHOW_NAVIGATION);
        carfilter.addAction(HIDE_NAVIGATION);
        carfilter.addAction(SHOW_STATUSBAR);
        carfilter.addAction(HIDE_STATUSBAR);
        context.registerReceiverAsUser(carBroadcastReceiver, UserHandle.ALL, carfilter, null, null);
        //End Add

        // listen for USER_SETUP_COMPLETE setting (per-user)
        resetUserSetupObserver();
}, cancelAction, afterKeyguardGone);
    }
    //Add By LYZK 2021/6/29
    private BroadcastReceiver carBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.e(TAG, "zjy--onReceive: " + intent);
            String action = intent.getAction();
            if (HIDE_NAVIGATION.equals(action)) {
                if (mNavigationBarView == null) return;

                mWindowManager.removeViewImmediate(mNavigationBarView);
                mNavigationBarView = null;
            }else if (SHOW_NAVIGATION.equals(action)) {
                if (mNavigationBarView != null) return;
               createNavigationBarView(context);
               addNavigationBar();
            }else if(HIDE_STATUSBAR.equals(action)) {
               //mStatusBarView.setVisibility(View.GONE);
               mStatusBarWindow.setVisibility(View.GONE);
           }else if(SHOW_STATUSBAR.equals(action)) {
               //mStatusBarView.setVisibility(View.VISIBLE);
               mStatusBarWindow.setVisibility(View.VISIBLE);
       
           }
        }
    };
    //End Add
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
}
        mContext.unregisterReceiver(mBroadcastReceiver);
        mContext.unregisterReceiver(mDemoReceiver);
        //Add By LYZK 2021/6/30
        mContext.unregisterReceiver(carBroadcastReceiver);
        //End Add
        mAssistManager.destroy();

        final SignalClusterView signalCluster =
                (SignalClusterView) mStatusBarView.findViewById(R.id.signal_cluster);

先检测一下adb 是否正常工作

C:\Users\Administrator>adb devices
List of devices attached
GB8ZADV49V      device

发送隐藏导航栏广播

adb shell am -a "lyzk.intent.systemui.hidenavigation"

发送隐藏状态栏广播

adb shell am -a "lyzk.intent.systemui.hidestatusbar"
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值