Snippets

Muhammed Ballan NavBarManager Hide/Show soft navigation bar downside the screen in some android devices

Created by Muhammed Ballan last modified

import android.os.Build;

/**
 * Created by mballan on 15.09.2015.
 */
public class NavBarManager {

	public static void hideTaskBar() {

		new Thread(new Runnable() {
			@Override
			public void run() {
				int tryCounter = 5;// for max try times, which is gonna be reached only if device is not
				// rooted
				boolean changed = false;
				while(!changed && tryCounter >= 0) {
					try {
						// REQUIRES ROOT
						Thread.sleep(800);
						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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.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();
						changed = true;
					} catch (Exception ex) {
						ex.printStackTrace();
						changed = false;
					} finally {
						tryCounter--;
						try {
							Thread.sleep(800);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}
			}
		}).start();

	}

	public static void showTaskBar() {
		new Thread(new Runnable() {
			@Override
			public void run() {
				boolean changed = false;
				int tryCounter = 5; // for max try times, which is gonna be reached only if device is not
				// rooted
				while(!changed && tryCounter >= 0) {
					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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
							ProcID = "42"; // ICS AND NEWER
						}
						// REQUIRES ROOT
						Process proc = Runtime
										.getRuntime()
										.exec(new String[]{"su", "-c",
														"am startservice -n com.android.systemui/.SystemUIService"}); // WAS
						// 79
						proc.waitFor();
						changed = true;
					} catch (Exception ex) {
						ex.printStackTrace();
						changed = false;
					} finally {
						tryCounter--;
						try {
							Thread.sleep(800);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}
			}
		}).start();
	}
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.