Hide Status bar on Android Ice Cream Sandwich - android

I'm working in a launcher for Android ICS but I have a problem with tablets.
I can't hide the status bar. I have try it in Android 2.3.X and it's ok. The problem appears only with Android 4.0.
How can I hide it?

You can not get 100% true full screen in Android 4.0.
Use the following to dim the notification bar (aka. status bar, system bar)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
And use this to hide it
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
And, if I guess right, you are trying to achieve a "kiosk mode". You can get a little help with an app named "surelock". This blocks all the "home" and "back" actions.
It is still not perfect but this may be the best we can achieve with Android ICS.

It is possible to hide the statusbar on a rooted android device. The program Hidebar does this by killing the systemui process. The program is open source, so you can read all about it in the source code.
See http://ppareit.github.com/HideBar/.

You cannot get rid of the system bar on tablets. You may be able to get rid of the navigation bar and status bar on phones. Please read the "Controls for system UI visibility" section of the Android 4.0 SDK release notes.

I know my answer comes a bit late, but after assembling info from various places, I came up with this, which works ONLY ON ROOTED DEVICES:
private void KillStatusBar()
{
Process proc = null;
String ProcID = "79"; //HONEYCOMB AND OLDER
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
ProcID = "42"; //ICS AND NEWER
}
try {
proc = Runtime
.getRuntime()
.exec(new String[] { "su", "-c",
"service call activity "+ProcID+" s16 com.android.systemui" });
} catch (IOException e) {
Log.w(TAG,"Failed to kill task bar (1).");
e.printStackTrace();
}
try {
proc.waitFor();
} catch (InterruptedException e) {
Log.w(TAG,"Failed to kill task bar (2).");
e.printStackTrace();
}
}
This should eliminate the bottom bar on any rooted device and turn it into "kiosk" mode.

To hide status bar and navigation bar in android 4.0, we should use code below:
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

Building upon ppareit's answer.
You can not hide the navigation bar on most stock devices. However, there is a work around if you rooting the device is an option. Here are the steps for one solution:
Root device
Install and run Busybox (required for taking full advantage of rooted device)
Install HideBar from resource
In HideBar there is an option to run in 'Kiosk' mode, in which there is no way to re-display the navigation bar. Needless to say, you really need to be careful with this.

Related

menu button doesn't show on nexus 7

so I am facing this problem for long time. I've got Nexus 4 and Nexus 7 both running Android 4.3, and i've got application with targetSdkVersion="11"("I use 11 because any target sdk below 11 doesn't support multitouch for me). And the problem is that 3-dot menu shows on Nexus 4 but doesnt show on Nexus 7. 3 dot menu button on nexus 7 works only if I put targetSdkVersion="8" but then multitouch doesnt work
Nexus 4:
Nexus 7 :
code :
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
screenshots :
nexus 7
nexus 4:
In case you are specifically wondering why the button is not being shown the following rules apply when Android determines if a legacy menu button is needed:
If target API version is less than 11 it is shown on all devices
If target version is 11, 12, or 13 (i.e. tablet-only Honeycomb) Android assumes that your app has been designed for tablets and won't show a legacy button on tablets, but will on phones
If target is 14 or above (ICS and above), Android assumes your app is designed for tablets and phones and so the legacy button isn't shown.
But like the other answers say, you shouldn't be using this menu button. If you don't want an entire ActionBar, another option would to have a three-dot button in your activity which shows a menu using PopupMenu.
You should not be using that menu anymore. From the Menus documentation:
On Android 3.0 and higher, items from the options menu are presented by the action bar as a combination of on-screen action items and overflow options. Beginning with Android 3.0, the Menu button is deprecated (some devices don't have one), so you should migrate toward using the action bar to provide access to actions and other options.
Use an ActionBar.
The correct solution is to use an ActionBar but there may be some hacks to get the overflow menu to appear.
Specifically, there's a hidden window flag FLAG_NEEDS_MENU_KEY you can access via reflection. Here's a code snippet (from this blog):
public static void addLegacyOverflowButton(Window window) {
if (window.peekDecorView() == null) {
throw new RuntimeException("Must call addLegacyOverflowButton() after setContentView()");
}
try {
window.addFlags(WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null));
}
catch (NoSuchFieldException e) {
// Ignore since this field won't exist in most versions of Android
}
catch (IllegalAccessException e) {
Log.w(TAG, "Could not access FLAG_NEEDS_MENU_KEY in addLegacyOverflowButton()", e);
}
}
I tested this on a couple of Nexus devices and it works. Comments on the blog state that there are devices where it doesn't work. Use with caution. And use an ActionBar, really.
There's a simple way to force a menu option to stay in the menu overflow. If you're creating a menu with XML, you can force this using the "showAsAction" attribute.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_option"
android:showAsAction="never"
android:title="#string/option_name" />
</menu>
If you set "showAsAction" to "never", it will be forced to don't show on the ActionBar, so the option will remain on the menu overflow.
There's more info (like how to vinculate the XML menu file to an Activity) on the official Android documentation webpage: http://developer.android.com/guide/topics/resources/menu-resource.html
I wish this can be helpful!
I wouldnt always recommend using this, since its a hack which breaks the consistency of the phone, but if you want the "3 dots" menu, which is called the overflow menu you need to add this method
//Hack to display overflowMenu on devices with a menu button
private void getOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
And in your onCreate() call this method.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Activity);
getOverflowMenu();
}

Transparent notification bar with live wallpaper on Galaxy S4

Full Edit since it apparently wasn't clear that this is indeed a programming question
On the Galaxy S4, the notification bar is transparent by default. When using the built-in "Bubbles" wallpaper this looks as follows for example:
Now I have developed my own live wallpaper. For sake of simplicity, I just fill the available canvas with 0xFFFF0000 for the screenshots, but normally it shows a different scene. On the Galaxy S4, my wallpaper does not show a transparent notification bar, but the default black one:
I noticed that sometimes my wallpaper shows a transparent bar also, here on the lockscreen. However, I was unable to reliably reproduce the behaviour.
My question is simply: is there any way to reliably enable the transparent notification bar from my wallpaper code or manifest? Actually, the unpredictable switching between transparent and black bar makes the user experience much worse than just with an always-black bar.
This is indeed possible on an unrooted S4:
public static boolean setTransparentNotificationBarTouchWiz(View view) {
try {
Field field = View.class.getDeclaredField("SYSTEM_UI_FLAG_TRANSPARENT_BACKGROUND");
Class<?> t = field.getType();
if (t == int.class) {
int value = field.getInt(null);
view.setSystemUiVisibility(value);
return true;
}
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}
return false;
}
My thanks to Kevin # TeslaCoil for sharing this flag with me.
Sorry, unless you are making a custom ROM this isn't possible, unless you only want the status bar changed for your app.
This would require a heck of a lot of work.
First you will need to add Theme.NoTitleBar.Fullscreen to your manifest
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
Then once you have done that you need to create a standard layout which represents the status bar, this would mean that you have to add the time, and also receive all the notifications from other apps, I do not personally know how to do that but I'm sure there is a way.
If you really want to do this goodluck, you have a hard time ahead of you.

How to hide bottom system bar in android tablet

I am developing an application for tablet only, where the requirement is to run the app on the full screen of the tablet.
For this I have used following code in my main activity:
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
This code snippet only removes the title bar and action bar. But in tablets, there is a bottom system bar (having home and back button). I also want to remove or hide this system bar too.
I have searched but there is only following solution:
There is no API to remove or hide the system bar.
You can use some android app to hide system bar. (for example:
surelock, hidebar, etc)
My question is :
Is it really not possible in android?
Above available app (i.e surelock, hide bar, etc) also hiding bar.
It means they are using something to do so. Can be use this
something in our app so the user will not require to download these
app seperatly.
Please guide me.
I know this is not a good idea. But My app is only for tablet having Android 4.0 or greater and that tablet will run only this single app so we do not need to go back and use home button. That's why my requirement is to use the app in full screen.
If you have root access you can use this code other wise it is not allowed
try{
//REQUIRES ROOT
Build.VERSION_CODES vc = new Build.VERSION_CODES();
Build.VERSION vr = new Build.VERSION();
String ProcID = "79"; //HONEYCOMB AND OLDER
//v.RELEASE //4.0.3
if(vr.SDK_INT >= vc.ICE_CREAM_SANDWICH){
ProcID = "42"; //ICS AND NEWER
}
//REQUIRES ROOT
Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity "+ ProcID +" s16 com.android.systemui"}); //WAS 79
proc.waitFor();
}catch(Exception ex){
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
See this
From Android API 4.0 and later you can use the following code to hide the bottom system bar.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
This is not possible unless you've root access. Alternatively, you can create a launcher application.
Otherwise it will be beyond the scope of your Application to Hide System/Navigation bar.
After a lot of searching on the internet, I managed to get the System Bar to hide and appear in a 4.2 device using:
To Hide:
Runtime.getRuntime().exec("service call activity 42 s16 com.android.systemui");
Or use 79 instead of 42 for API less than 14. You may also need to include the SET_DEBUG_APP permission, in which case you need to have the application signed with the system key or installed in the /system/app/ directory.
To Show:
Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");
Alternatively some people have used the -a (instead of -n) option, though this was causing an error on my device:
Error: Not found; no service started.

Honeycomb 3.1 / Mono for Android persist 'LightsOut'

I developed my app using Mono for Android. I have the latest version 4.0.3. My AndroidManifest.xml specifies:
<uses-sdk android:targetSdkVersion="11" android:minSdkVersion="8" />
The app runs on tablets, so in Honeycomb I need to hide the status bar at the bottom of the screen. This is how I do that (with a simple extension method):
internal static void LightsOut(this View view)
{
try
{
IntPtr view_setSystemUiVisibility = JNIEnv.GetMethodID(view.Class.Handle, "setSystemUiVisibility", "(I)V");
JNIEnv.CallVoidMethod(view.Handle, view_setSystemUiVisibility, new JValue(1));
}
catch
{ }
}
I call this on every view that I instantiate. On my Motorola Xoom, running 3.0.1, this works great.
On my Samsung Galaxy Tab running 3.1, it works; but the status bar comes back after some short period of time. In the Android Log I see that LightsOn() is getting called...
How can I prevent the status bar from coming back in 3.1? I saw this event:
http://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html
And thought I could use it to hide the status bar, if it comes back. But I don't see how I can subscribe to it (it doesn't show in Intellisense).
Does something specific happen before the status bar comes back, or is it solely time related? A quick search of the ICS source suggests that the status bar status will be reset when the top App Window changes. Are you calling StartActivity() or moving to another app when you see this behavior?
The View.OnSystemUiVisibilityChangeListener interface has been bound as the View.IOnSystemUiVisibilityChangeListener interface and through the View.SystemUiVisibilityChange event. However, both of these mechanisms require that your $(TargetFrameworkVersion) target Android v3.1 or later, which would set your //uses-sdk/#android:minSdkVersion attribute to 12, and is thus something you (presumably) don't want to do.
I see two plausible solutions here:
Figure out why LightsOn() is being invoked and try to work around it (call LightsOut() within every Activity.OnCreate() method?).
Provide two versions of your app, one with a minSdkVersion of 8, and one of (at least) 12, and then use Multiple APK Support to include both in your program. The device will then run the appropriate package, permitting access to the View.SystemUiVisibilityChange event.

Hiding Systembar in android 3.0(honeycomb)

How do I hide the system bar in android 3.0(honeycomb)?
The systembar cannot be removed (on non-rooted devices). You can go into "lights out mode" which dims it and only shows dots where the buttons are using the following code (ref):
View v = findViewById(R.id.view_id);
v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
This was also asked before here, remember to search first.
We tinkered around with Honeycomb and found a way to hide and restore the bar, although root is required here. You can find a detailed answer in our article here.
I tested some ways to kill system bar:
Kill by adb shell: - su; ps, look for com.android.systemui; kill - success, sys-bar removed.
Settings, "Sytem UI" force stop - success, sys-bar removed.
Root explorer, delete /system/app/systemui.apk - got circle of error messages "com.android.systemui crashed, blabla...". Reboot, tablet started without system bar, no any errors, so success.
My app:
Code:
android.os.Process.killProcess(android.os.Process.getUidForName("com.android.systemui"));
failed, as expected, because my app can not kill process started by another app.
My app:
permission - android.permission.KILL_BACKGROUND_PROCESSES
Code:
final Context context = getApplicationContext();
servMng = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
servMng.killBackgroundProcesses("com.android.systemui");
Failed, no idea why.
Run script in my app to execute "ps", look for PID and execute "kill", not tested.
Hiding the systembar in honeycomb can be done with Hide Bar. The home page is at http://ppareit.github.com/HideBar/. The code can be found at https://github.com/ppareit/HideBar.

Categories

Resources