Reputation: 1428
I'm trying to hide the system Status Bar on an Android 4.4 device. This is for a kiosk-mode where my app will be the only app ever run on the device. The target device for now is a 2013 Nexus 7.
The device is rooted, and I've been able to completely remove the bottom Navigation Bar with some info from this post.
For the top Status Bar, everything I have tried only hides the bar temporarily. If my users motion down at the top of the screen, the status bar reappears. I don't want to allow them to see the time, get to settings or even see notifications.
Posts I've found and already tried:
Any suggestions?
Ideally, I'd love to be able to edit build.prop to do this, since I'm already doing that for the navigation bar, and could do this at the same time. I'm trying to not have to build my own android image.
Update:
After some more work, this seems to depend somewhat on the exact build of android, or the device its running on.
Some devices, such as the Nexus series I've been working with allow the user to swipe to make the bar reappear.
However, I've recently tried this on a Verizon Eclipse, and the bar does not reappear, which is what I was looking for.
I'm still looking for a better solution to target all devices, but it will probably come down to creating my own build of android.
Upvotes: 38
Views: 50397
Reputation: 161
For rooted devices, I use the follwing code to change visibility from within my apps. It sets the visibility of the System UI and then reboots the device to make the setting changes actually happen. You can also use "pm "hide" com.android.systemui"... via adb, of course.
Please note that on some older devices, the command parameters were "enable" / "disable". For newer Android versions (9+), I observed that only "unhide" and "hide" were working for me.
fun setSystemUiEnabled(enabled: Boolean) {
try {
val p = Runtime.getRuntime().exec("su")
val os = DataOutputStream(p.outputStream)
os.writeBytes(
"pm ${if (enabled) "unhide" else "hide"} com.android.systemui\n"
)
os.writeBytes("reboot\n")
os.writeBytes("exit\n")
os.flush()
} catch (e: IOException) {
Timber.w(e, "Error while setting system-ui enabled-state to $enabled")
e.printStackTrace()
}
}
Upvotes: 0
Reputation: 94
try this code:
disable statusbar and navbar
adb shell
su
pm disable com.android.systemui
reboot
enable statusbar and navbar
adb shell
su
pm enable com.android.systemui
reboot
It works on Android 5.1.1 but the usb camera is down
Another way (my device worked without any problems)
Remove System Navigation Bar ¶ The Android System Navigation Bar is the bar at the bottom of the screen which presents the back, home, and app-switch soft-keys.
As the system navigation bar is independent from any installed Android application in particular, removing it is done in the Android OS.
To accomplish this on a rooted installed device you can set the qemu.hw.mainkeys property to 1 by editing /system/build.prop:
qemu.hw.mainkeys=1
To accomplish this at build time you would set the 'config_showNavigationBar' value to false in your device overlay (ie device/gateworks/ventana/overlay/frameworks/base/core/res/res/values/config.xml):
<bool name="config_showNavigationBar">false</bool>
Note you could also make build.prop modifications at build time by adding to the PRODUCT_DEFAULT_PROPERTY_OVERRIDES or ADDITIONAL_BUILD_PROPERTIES variables which can be found in your device target configuration (ie imx6.mk and BoardConfig.mk in device/gateworks/ventana/).
Additionally, you can hide the navigation bar (and status bar) within an application by setting the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag however it will pop back if the user touches anywhere on the screen. http://trac.gateworks.com/wiki/Android/Kiosk
Upvotes: 1
Reputation: 1233
I've used this answer to hide the softkeys: https://stackoverflow.com/a/27003890/1525867
And for disabling the StatusBar (this may harm your device so do it carfully. I've ruined my device several times before I managed to do it) Tested on Asus Tinker Board, Android 6:
path
in your favorite waypull SystemUI.apk
from your device:
adb pull /system/priv-app/SystemUI/SystemUI.apk
the path to SystemUI.apk
may be different
pull framework-res.apk
from your device adb pull /system/framework/framework-res.apk
the path to framework-res.apk
may be different
run apktool if framework-res.apk
run apktool if SystemUI.apk
run apktool d SystemUI.apk
Open SystemUI\res\layout\status_bar.xml
and add android:visibility="gone"
to the top most xml element (for me it was com.android.systemui.statusbar.phone.PhoneStatusBarView
)
run apktool b SystemUI
Go to SystemUI\original
and copy AndroidManifest.xml
and META-INF
to SystemUI\build\apk\
run apktool b SystemUI
again
Go to SystemUI\dist\
and override the device's original SystemUI.apk
with the one at SystemUI\dist\SystemUI.apk
with adb push SystemUI\dist\SystemUI.apk /system/priv-app/SystemUI/SystemUI.apk
Restart device
Based on this thread https://forum.xda-developers.com/showthread.php?t=2203166
Upvotes: 4
Reputation: 560
I know this is an old question but hopefully it will help someone. Here are two very simple calls to disable and enable the status bar that I have used before. Can be used from the command line or executed by a Java app:
Disable:
service call activity 42 s16 com.android.systemui
Enable:
am startservice -n com.android.systemui/.SystemUIService
Upvotes: 19
Reputation: 1911
We could not prevent the status appearing in full screen mode in kitkat devices, so made a hack which still suits the requirement ie block the status bar from expanding.
For that to work, the app was not made full screen. We put a overlay over status bar and consumed all input events. It prevented the status from expanding.
note:
Updated
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
customViewGroup implementation Code :
WindowManager manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
Hope this helps you
Upvotes: 28
Reputation: 9103
A great solution I found for that issue, setting each Activity theme
& windowSoftInputMode
to the following values :
<activity android:name=".MyActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="adjustResize"> <!-- theme : to set the activity to a full screen mode without a status bar(like in some games) -->
</activity> <!-- windowSoftInputMode : to resize the activity so that it fits the condition of displaying a softkeyboard -->
for more info refer here.
Upvotes: 2
Reputation: 1428
I did try the workaround provided by @gonglong, but I wasn't happy with the result because of a flash in the UI as the workaround kicked in.
Instead, I was able to do this as root:
settings put secure user_setup_complete 0
I think on a normal device, this would cause the initial device setup to start, but on my devices, I've removed that APK from system so that doesn't happen.
This isn't documented anywhere I can find, but has a nice effect, where the top settings UI can't be dragged down. The notifications area can still be dragged down.
Another setting that I found useful was:
settings put global device_provisioned 0
This hides the Airplane Mode and Silent Mode options from the Power menu, which is an added bonus for my application.
There might be more side effects, but I've yet to find any that matter to me.
This list was taken from a Nexus 7 2013 LTE running brand new Android 4.4.3 (KTU84L). The number in square brackets is the value when I pulled the db file, which was after basic setup device setup and enabling developer/USB, but before making any other changes in settings
This file was found at data/data/com.android.providers.settings/databases/settings.db
Note: Some URLS required adding an extra space character to bypass SO filters
system
namespaceglobal
namespacesecure
namespaceUpvotes: 22
Reputation: 592
I don't have a perfect solution but a workaround here. The basic idea is to listen the system ui status changes and force navigation/status bar as invisible. It takes effect as similar as setting IMMERSIVE_STICKY mode but disappearing navigation/status bar quicker than IMMERSIVE_STICKY.
here it is:
set system ui style in onCreate() and on onResume function, and set system ui change listener
mDecroView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
mDecroView.setOnSystemUiVisibilityChangeListener(this);
force system bar as invisible in onSystemUiVisibilityChange, setting system ui some seconds later otherwise it would take on effect(does not know exactly why, maybe system just ignores the system ui setting request when system bar showing not yet completed)
public void onSystemUiVisibilityChange(int visibility) {
// TODO Auto-generated method stub
Log.d(TAG, "onSystemUiVisibilityChange called with visibility " + visibility);
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0){
if(null == mHandler){
mHandler = new MyHandler();
}
if(null != mHandler){
mHandler.removeMessages(MSG_HIDE_SYSTEM_BAR);
mHandler.sendEmptyMessageDelayed(MSG_HIDE_SYSTEM_BAR, 50);
}
//the deccro view is not in full screen
Log.d(TAG, "setSystemUiVisibility");
Log.d(TAG, "current system ui is " + mDecroView.getSystemUiVisibility());
}
}
then you can set system ui like this:
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch(msg.what){
case MSG_HIDE_SYSTEM_BAR:
mDecroView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
break;
}
}
Upvotes: 2
Reputation: 89
add this before : setContentView(R.layout.x);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.x);
Upvotes: -1