全志A40i Android7.1 动态隐藏 状态栏和导航栏

客户要求系统提供接口实现该功能,通过广播方式实现,

验证网友方案记录如下,对网友分享非常感谢:

代码如下;

 

+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -418,6 +418,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,

     private int mNavigationIconHints = 0;
     private HandlerThread mHandlerThread;
+    //Navigation
+    private static final String SHOW_NAVIGATION = "car.intent.systemui.shownavigation";
+    private static final String HIDE_NAVIGATION = "car.intent.systemui.hidenavigation";
+    private static final String SHOW_STATUSBAR  = "car.intent.systemui.showstatusbar";
+    private static final String HIDE_STATUSBAR  = "car.intent.systemui.hidestatusbar";

+    //Navigation

     // ensure quick settings is disabled until the current user makes it through the setup wizard
     private boolean mUserSetup = false;
@@ -1003,6 +1009,14 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         demoFilter.addAction(ACTION_DEMO);
         context.registerReceiverAsUser(mDemoReceiver, UserHandle.ALL, demoFilter,
                 android.Manifest.permission.DUMP, null);
+//Navigatioin
+        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);
+//Navigation

         // listen for USER_SETUP_COMPLETE setting (per-user)
         resetUserSetupObserver();
@@ -3546,6 +3560,33 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         }, cancelAction, afterKeyguardGone);
     }

+//Navigation
+    private BroadcastReceiver carBroadcastReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            Log.e(TAG, "bluesky--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);
+
+           }
+        }
+    };

+//Navigation
+
     private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -3945,6 +3986,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         }
         mContext.unregisterReceiver(mBroadcastReceiver);
         mContext.unregisterReceiver(mDemoReceiver);
+        mContext.unregisterReceiver(carBroadcastReceiver);
+
         mAssistManager.destroy();

 

下边是添加开机自动根据前面的条件判断

@@ -697,6 +697,28 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         // in session state

         addNavigationBar();
+//
+       String NAVIGATION_ACCESS_PROPERTY = "persist.sys.navigation_access";
+        String value = SystemProperties.get(NAVIGATION_ACCESS_PROPERTY, "0");
+       if ( "0".equals(value))
+       {
+              if (mNavigationBarView == null) return;
+
+              mWindowManager.removeViewImmediate(mNavigationBarView);
+              mNavigationBarView = null;
+
+             mStatusBarWindow.setVisibility(View.GONE);
+
+       }//else is not default set,the main problem is how to hide the navigation and the status
+       /*
+       else if("1".equals(value))
+       {
+               if (mNavigationBarView != null) return;
+               createNavigationBarView(context);
+               addNavigationBar();
+              mStatusBarWindow.setVisibility(View.VISIBLE);
+       }*/
+//

 

 

App添加按钮实现函数:

public void showbar(View view) {

    Intent i = new Intent("car.intent.systemui.shownavigation");
    sendBroadcast(i);
    Intent status = new Intent("car.intent.systemui.showstatusbar");
    sendBroadcast(status);
}

public void hidebar(View view) {

    Intent i = new Intent("car.intent.systemui.hidenavigation");
    sendBroadcast(i);
    Intent status = new Intent("car.intent.systemui.hidestatusbar");
    sendBroadcast(status);
}

 

当然可以通过app实现隐藏app api也可以,但是发现触摸屏幕状态栏能够显示出来;有些问题,方法也写出来:

在Activity的onCreate方法中添加如下方法即可

 Window window = getWindow();
 WindowManager.LayoutParams params = window.getAttributes();
 params.systemUiVisibility =  View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_IMMERSIVE;
 window.setAttributes(params);

 

完整的代码如下:

https://download.csdn.net/download/dongguangit/13064967

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页