Android / How-To

How-To Create Kiosk Mode on the Nexus 7

With Google’s release of the Nexus 7, hackers have access to a very high-quality touchscreen at relatively low cost that runs Google’s latest code.  This makes the Nexus an obvious target for customization and projects.  Some of these applications require what I call “Kiosk Mode” or “Single Application Mode”, where the display is locked into a single application that can not be exited, and normal UI components like the status bar and the navigation bar are inaccessible. Furthermore, restarting the unit should boot you into that application, and power-loss situations should be handled by an automatic restart of the system.

I was surprised that I could find no clear guide to accomplishing this. I did find many incomplete solutions, and I even found several posts claiming it couldn’t be done.  Obviously that wasn’t acceptable, so after some research I came up with a combination of techniques that create a solid and reliable kiosk mode for the Nexus 7.

This tutorial assumes you are already set up for Android development with Eclipse, Netbeans, or some other IDE, and have ADB and the Android SDK’s installed.  Also, the Nexus I am testing with is running Android version 4.2.2.

WARNING: This does involve rooting your Nexus and modifying system settings with an accompanying risk of bricking your device. If that doesn’t scare you off, then read on… I am breaking it down into three easy steps.

Step 1: Suppress the Title Bar & Make Your App a Launcher

You build your app more or less like a normal app, but with a couple key exceptions:

  1. AVOID anything that can start another app. For instance, a web link that isn’t handled correctly could launch a browser. Don’t do that.
  2. You must add the HOME intent to your main activity… this will allow it to be set as the default when the phone is powered on.
  3. You must suppress the title bar in your theme or activity.

To suppress the titlebar, I find it easiest to inherit from the theme I want, then put the title bar suppression in my theme file. That way it’s all in one place.

/res/values/themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<style name="mytheme" parent="@android:style/android:Theme.Holo.Light">
		<!-- Window attributes -->
		<item name="android:windowFullscreen">true</item>
		<item name="android:windowContentOverlay">@null</item>
		<item name="android:windowActionBar">false</item>
		<item name="android:windowNoTitle">true</item>
	</style>
</resources>

These four entries will prevent the status bar and title bar from showing. Once you have created your theme,  reference the it at the application level in your AndroidManifest.XML, see line 9 below.

Also in the manifest, you need to add your HOME intent. This is seen on line 19.  Don’t be confused by the other intents.  DEFAULT means the activity is the default for your app… the activity to run first.  LAUNCHER means an icon for your app will be added to the list of apps in the default launcher. MAIN is just a name for your activity, albeit one commonly used for the default activity.

/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.kiosk"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="17"/>
    <application
            android:label="@string/app_name"
            android:theme="@style/mytheme">
	<activity android:name=".MAIN"
                  android:label="@string/app_name"
                  android:screenOrientation="sensorLandscape"
                  android:hardwareAccelerated="true"
		>
            <intent-filter>
	            <action android:name="android.intent.action.MAIN" />
	            <category android:name="android.intent.category.DEFAULT" />
	            <category android:name="android.intent.category.LAUNCHER" />
	            <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </activity>
    </application>
</manifest>

If you upload your app and then hit the HOME button, you will note a popup letting you choose which launcher to use, with your app as one of the options.  Congrats, you just built your first launcher.

Launcher chooser popup

Step 2: Root Your Tablet

There are plenty of guides on how to do this, so I’m not going to cover it in detail.  I used the Nexus 7 Toolkit by mskip of XDA.  Make sure to read carefully, upgrade the Toolkit if necessary, and consider making your life easier by purchasing the paid version.

You will probably lose all your apps and settings when you root, so back up your files if they are important.

Step 3: Modify System Files and Settings

There are only a couple of modifications you need to make.

Change # 1 – Hide the Navigation Bar

The first is a change to /system/build.prop that will permanently hide the Navigation bar (the one with BACK, HOME, and RECENT APPS).  Assuming you have the Android SDK installed and the Android Development Bridge (adb.exe) is in your path, you can download build.prop as follows… open a command window and enter:

adb pull /system/build.prop

Then open build.prop in a text editor and add the following line to the end:

#
# BLAME THEBITPLAGUE FOR THIS
#
qemu.hw.mainkeys=1

Save the file and exit the text editor, and then do the following to upload it:

adb push build.prop /system/build.prop

Note: if you get an error about the file system being read only when you try to push, use the “Pull Files”/”Push Files” options in the Nexus toolkit instead of stock ADB. This makes it easy.

According to some comments I have read, you may need to clear your Dalvik cache, though I didn’t have to. As soon as I rebooted, the navigation bar was gone.

Note: having no Navigation bar can make it difficult to navigate! Consider installing a home button replacement like Button Savior until you are done with your dev process.

Thanks to lesdense from XDA forums for the build.prop entry.

Change # 2 – Change the behavior when plugging in charger

This is an important step if your kiosk or installation is going to cover the hardware buttons. You don’t want a power shortage that results in the battery running down and getting turned off to necessitate opening up your enclosure to hit the power button.  What we want is that anytime the device is in the off state, and then power is added via the USB port, that the unit will automatically turn on. Luckily this is an easy change… start up your command line and then enter the following command:

fastboot oem off-mode-charge 0

Now unplug your device and power it off. Then plug it back it in… rather than showing the “charging” animation, it will go straight to powering on.

Kudos to trevd at the XDA forums for this post that provided the off-mode-charge tip.

The Final Result

In this demo, my app just displays a plain background to make it clear there are none of the usual controls. There is no status bar, no menu bar, and the long hold and swipe inputs have no effect. Best of all, the unit powers on by itself  when connected to power.   This Nexus could now be installed into an auto dashboard, a public information kiosk, or other single-use applications.

Advertisements

58 thoughts on “How-To Create Kiosk Mode on the Nexus 7

      • No, it doesn’t 🙂 I managed to soft-brick a huawei tablet by changing the build.prop file. I’m not sure if it was because of the changes or because I messed with the system directory permissions but it didn’t work as expected. After restoring it and re-rooting it, I was able to hide the bottom bar with the following java code (the application needs root access):

        try
        {
        String command;
        String[] envp = null;
        command = “LD_LIBRARY_PATH=/vendor/lib:/system/lib service call activity 42 s16 com.android.systemui”;
        Process proc = Runtime.getRuntime().exec(new String[] { “su”, “-c”, command }, envp);
        proc.waitFor();
        }
        catch(Exception ex)
        {
        Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
        }

  1. Awesome! However, Will the command “fastboot oem off-mode-charge 0” work with other devices like Nexus 10 or Galaxy tab 10.1?

  2. Hi – I’m looking for a kiosk app just like this but which opens a web browser to a particular page. The app also needs to have a sneaky exit feature in case we need to get back to the home screen. Would you be interested in adding a few more tweaks to your app to accomplish this for some dollar in return 😀

  3. Has anyone tried qemu.hw.mainkeys=1 on a Nexus 10?
    seems to be really messing up for me.
    screen goes black after re-booting (right after the white Google logo).
    don’t even get the Jellybean-X.

    If I try to re-push the original file after, it doesn’t seem to resolve the issue either.

    • Does the Nexus 10 have the nav bar that combines with a clock and access to settings? If so that is called a “system bar”, and it works differently from the nav bar.

      • Turns out it was a file-permissions thing. After pushing the modified build.prop (using skipsoft’s Toolkit), if you don’t reset the permissions back to 644, Android will not boot properly.

  4. I am using Codeproof MDM and Codeproof App Manager app(home-app) to run my Android devices in Kiosk mode. I’ve used the above article to hide the “notification bar” permanently. works great!

    • You would have to call system settings from within your app. I haven’t tested this, but it should be similar to:

      final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.wifisettings");
      intent.setComponent(cn);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setFlags(Intent.FLAG_FROM_BACKGROUND);
      startActivity( intent);

      Hook that up inside an onclick and you’re set.

  5. tried after first installing button saviour but without first creating a launcher app. My nexus boots to a blank screen and had no way to get out other than doing a full recovery. I assumed that the button saviour app would allow me to navigate out of kiosk mode?

  6. For step1 ‘Suppress the Title Bar & Make Your App a Launcher’, is there any way to bypass the default lock screen + clock when the device receives power and boots up?

  7. Confirmed. The build.prop hack doesn’t seem to work on a Nexus5. Everything else does. So just need a way to hide the System toolbars on a Nexus5 and I’m good to go.

    • Correction, had to unmount my system first in order to properly edit the build.prop file. Works!!! Only remaining item is removing the very top bar with wifi, battery and time icons viewable on swipe from top. Thanks again for posting this!

  8. Pingback: Permanently hide Android Status BarCopyQuery CopyQuery | Question & Answer Tool for your Technical Queries,CopyQuery, ejjuit, query, copyquery, copyquery.com, android doubt, ios question, sql query, sqlite query, nodejsquery, dns query, update query,

  9. I have a couple of questions, how do you disable the swipe down gesture that shows the status bar?

    And do you have text input in your app? If so how do you keep the user from not entering settings via the input settings button on the keyboard.

    • The only settings you can access from the keyboard are for the keyboard itself, not any other settings. If you don’t want the user to access those, you can see if the keyboard settings allow you to disable the keyboard settings access. If it doesn’t, you can create your own IME that doesn’t have access to any settings, but that’s a ton of work. Another option that I did was to stop the IME from popping up by creating my own EditText that overrides onTouchEvent and returns true to consume the event. Then I created my own KeyboardView that I can include on a layout that has the EditText to allow text entry. This was a fair amount of work too, but less than creating an IME. It also gives me total control over what keys to include in the keyboard which I needed.

  10. I’ve implemented fastboot oem off-mode-charge 0 on my Nexus 7. Now when the battery is totally dead, I plug it in and it’s stuck in bootmode forever because not enough juice to boot right away. Do you know a way around this?

    • tell your app to power down the device before it is completely dead. I use the same setting as kiosk mode and just power down our devices if battery < 50% AND unplugged() ;). You really should avoid discharging your battery completely, it can damage it permanently.

    • Sorry to hear it. What device do you have? Nexus are hard to permanently brick.

      A recovery is not such a big deal anyway. If you are hacking on your device, get used to doing them.

  11. If you get to Step 2 and can not push the build.prop file into the /system folder as described by the author. The work around is this:
    1. copy the build.prop file into /sdcard instead by logging into your device:

    adb push build.prop /sdcard
    adb shell

    2. Now inside your device remount your /system and copy that file over by doing:

    su
    mount -o remount,rw /system
    cp /sdcard/build.prop /system/build.prop
    reboot

    Of course this works only if you have root access to your device.
    Good luck!

  12. Hi there! Great article. My new toy hasn’t arrived yet, but do you think your solution should work on other Android devices like MK809 III Android TV dongles? I’ll sure try it myself, but maybe someone here have experienced with other devices and will save from bricking my little device…LOL. Thanks

  13. Pingback: Permanently bury Android Status Bar - Zielesch Gyan

  14. Hi and thanks to the How To, it’s been very useful. One question that I have and other had have is regarding how to disable the status bar after doing a swipe down gesture in the top of the screen. I understand that giving the correct definition of your theme should be enough but with the plain example you give in section one that can’t be achieve. Do you know what other option add to the theme to hide permanently the status bar.

    (The launcher and hide nav bar step works like a charm!)

  15. fastboot oem off-mode-charge 0 is not working on motorola? Can you suggest any command for Moto E

  16. Hello VT,

    Your article looks very well hope it will helpful for my Nexus 7. I just want to say thank for sharing your informative article with us.

    Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s