Platform: RK3368
OS: Android 6.0
Kernel: 3.10.0
先修改SystemUI支持广播接收可以显示或者隐藏系统界面:frameworks/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
......
else if (Intent.ACTION_SCREEN_ON.equals(action)) {
notifyNavigationBarScreenOn(true);
}
else if (action.equals("action.HIDE_SYSTEMUI")) {
setSbNbVisibility(View.GONE);
}
else if (action.equals("action.SHOW_SYSTEMUI")) {
setSbNbVisibility(View.VISIBLE);
}
}
};
private void setSbNbVisibility(int visibility) {
Log.d(TAG, "setSbNbVisibility " + visibility);
if (visibility == View.GONE && mNavigationBarView != null && mStatusBarWindow != null) {
try {
mWindowManager.removeViewImmediate(mNavigationBarView);
mStatusBarWindow.setVisibility(View.GONE);
} catch (IllegalArgumentException e) {
Log.w(TAG, "IllegalArgumentException: " + e);
}
mNavigationBarView = null;
} else if (visibility == View.VISIBLE && mNavigationBarView == null && mStatusBarWindow != null) {
try {
makeNavigationBarView();
addNavigationBar();
mStatusBarWindow.setVisibility(View.VISIBLE);
} catch (WindowManager.BadTokenException e) {
// ignore
Log.w(TAG, "BadTokenException: " + e.getMessage());
} catch (RuntimeException e) {
// don't crash if something else bad happens, for example a
// failure loading resources because we are loading from an app
// on external storage that has been unmounted.
Log.w(TAG, "RuntimeException: " + e);
}
}
}
private void makeNavigationBarView() {
mNavigationBarView = (NavigationBarView) View.inflate(mContext, R.layout.navigation_bar, null);
mNavigationBarView.setDisabledFlags(mDisabled1);
mNavigationBarView.setBar(this);
mNavigationBarView.setOnVerticalChangedListener(
new NavigationBarView.OnVerticalChangedListener() {
@Override
public void onVerticalChanged(boolean isVertical) {
if (mAssistManager != null) {
mAssistManager.onConfigurationChanged();
}
mNotificationPanel.setQsScrimEnabled(!isVertical);
}
});
mNavigationBarView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
checkUserAutohide(v, event);
return false;
}
});
}
然后自己应用中发送广播实现显示和隐藏系统界面:
public static void hideSystemUI(Context context, boolean hide) {
Intent intent = new Intent();
intent.setPackage("com.android.systemui");
if (hide) {
intent.setAction(ACTION_HIDE_SYSTEMUI);
} else {
intent.setAction(ACTION_SHOW_SYSTEMUI);
}
context.sendBroadcast(intent);
}