由于公司项目需要动态显示和隐藏导航栏和状态栏,所以就需要从底层代码加入广播命令,下面是实际操作过程。
一、文件路径
/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"