Implementing Kiosk Mode in Android - Part 1

Posted by admin at 11:08 AM on Oct 4, 2013

Share:


Part 1: No Android Changes Required

Note: Looking for Kiosk mode in Android Lollipop 5.0 or later? Skip to part 3.

What is “Kiosk Mode” and why would you want to use it? Kiosk Mode basically allows a single Android application to have full control of the system. The user is prevented from leaving the current application or running other applications. Think of a hypothetical ATM machine that is running Android. It would be bad if the user could get out of the “ATM app” and start poking around with the underlying system.

In this article we provide a brief overview of how Kiosk Mode can be implemented without any modifications to the Android operating system, and we provide a sample Eclipse app that you can use as a template for writing your own Kiosk Mode apps.

Kiosk Mode is implemented by disabling certain Android features that can be used to leave the current application or start a new application. Specifically, we need to disable or change the following features of Android:

  • The Home key
  • The Back key
  • The Power button
  • The “notification drawer” or “status bar”

Unfortunately, Android does not come with a full-fledged Kiosk Mode that we can simply turn on. Instead, we need to disable or change the behavior of each of the four features individually.

The Home key

The Home key brings you back to the Home screen, even if you are running another application. Technically, the Home key runs whatever Activity is currently bound to the “HOME” Intent. This Intent is bound by default to the built-in “Launcher” application that comes with Android.

There are two ways that we can have the Home key give our application control instead of the Launcher. To permanently bind the Home key to our app, we need to have our app’s main Activity claim the “HOME” Intent for itself. Unfortunately, in current versions of Android we cannot take the “HOME” Intent from the Launcher, so we will actually have two applications that have claimed the “HOME” Intent, and Android will ask us to decide which application we want to run each time the Home key is pressed, unless we choose a default application. The only way to get around this and forcefully make our app the default HOME app is to actually uninstall the Launcher application, which may not be possible.

Or, we can temporarily bind the Home key to our app by entering Car Mode, claiming the “CAR_DOCK” Intent, and temporarily binding the Home key to the “CAR_DOCK” Intent instead of the “HOME” Intent. This is what we do in our sample application.

The Back key

The Back key is a lot easier to deal with. We simply need to have our application intercept it and ignore it instead of passing it through to Android, which is the default.

The Power button

The Power button is a problem because when you turn the screen back on the “keyguard” or “lock screen” will be shown instead of our app. So what we have to do is set a flag in our app that tells Android to show our app instead of the keyguard.

The Notification Drawer

To keep users from accessing the notification drawer, we run our app in full-screen mode. Problem solved.

The further details, please see our sample Eclipse project: CarModeDemo.zip

A few remaining problems

There are a few problems with our Kiosk Mode implementation:

  • Our application will never see the Home key. Pressing the Home key will always take us back to our app’s main Activity, even if that’s not what we want.
  • If we long-press the Home key, Android will show us a list of recently-run apps that we can switch to.

In an upcoming article, we will describe how to implement a better Kiosk Mode that avoids these problems, but does require making some changes to Android itself.

Update: Google is adding this capability to Android L, and calling it Task Locking. More information to come...

Read Part 2, Part 3, and Part 4.


Loading Conversation