This article describes a list of powerful methods to implement a Kiosk Mode in Android. A Kiosk Mode is useful if you develop an Android app and want prevent any other applications to run in the foreground.

Not a software developer? Turn any Android tablet or phone into a Kiosk.
Use SureLock to lock them down to only one or a few specific apps.

A few things to consider

  • Exit mechanism: Don’t forget to implement and test an exit mechanism in your Android Kiosk app.
  • Talk to your users: Be careful, if you want to distribute your Kiosk app through the Play Store. Tell your users how they can leave your app before they enter the Kiosk Mode.
  • Nothing is completely secure: There are techies like you out there who can bypass your restrictions if the device is not physically secured.



A Kiosk Mode is implemented by disabling various Android features that can be used to leave your app. The following features are affected:

  • The back button
  • The home button
  • The recent apps button
  • The power button
  • The volume buttons


First of all we need to make sure your Android Kiosk app starts automatically after booting your device.

Add the following permission as a child of the manifest element to your Android manifest:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

Now, your app has the permission to receive the RECEIVE_BOOT_COMPLETED broadcast. This message means that the phone was booted.

At next, add an intent filter to the manifest:

<receiver android:name=".BootReceiver">
    <intent-filter >
        <action android:name="android.intent.action.BOOT_COMPLETED"/>

Create a class called BootReceiver that extends BroadcastReceiver and add your code to the onReceive method to start your application:

public class BootReceiver extends BroadcastReceiver {

  public void onReceive(Context context, Intent intent) {
    Intent myIntent = new Intent(context, MyKioskModeActivity.class);

Disable the back button

This is a simple task: Just override onBackPressed in your Activity class. Please note that you can not override onBackPressed inside fragments!

public void onBackPressed() {
	// nothing to do here
	// … really      

Disable the power button

Sadly, disabling the power button is not possible without custom modification to the core of the Android operating system. Nevertheless, it is possible to detect the result of the button press and react on it.

Short power button press:

You can detect a short button press by handling the ACTION_SCREEN_OFF intent and kick the screen back to life with acquiring a wake lock. What a hack!

Please note that you can’t declare ACTION_SCREEN_OFF in the AndroidManifest.xml! You are only allowed to catch them while your application is running. For that reason, create a class called OnScreenOffReceiver that extends BroadcastReceiver and add the following code:

public class OnScreenOffReceiver extends BroadcastReceiver {
  private static final String PREF_KIOSK_MODE = "pref_kiosk_mode";
  public void onReceive(Context context, Intent intent) {
      AppContext ctx = (AppContext) context.getApplicationContext();
      // is Kiosk Mode active?
      if(isKioskModeActive(ctx)) {

  private void wakeUpDevice(AppContext context) {
    PowerManager.WakeLock wakeLock = context.getWakeLock(); // get WakeLock reference via AppContext
    if (wakeLock.isHeld()) {
      wakeLock.release(); // release old wake lock

    // create a new wake lock...

    // ... and release again

  private boolean isKioskModeActive(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getBoolean(PREF_KIOSK_MODE, false);

Create a subclass of Application and add the following code:

public class AppContext extends Application {

  private AppContext instance;
  private PowerManager.WakeLock wakeLock;
  private OnScreenOffReceiver onScreenOffReceiver;

  public void onCreate() {
    instance = this;

  private void registerKioskModeScreenOffReceiver() {
    // register screen off receiver
    final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    onScreenOffReceiver = new OnScreenOffReceiver();
    registerReceiver(onScreenOffReceiver, filter);

  public PowerManager.WakeLock getWakeLock() {
    if(wakeLock == null) {
      // lazy loading: first call, create wakeLock via PowerManager.
      PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
      wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "wakeup");
    return wakeLock;

Add the permission WAKE_LOCK to your manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />

Register your subclass of Application in your manifest (android:name=”.AppContext”):


To make the wake up a bit smarter, add the following line in your activity (before setContentView is called!). This line deactivates the lock screen:


For example:

protected void onCreate(Bundle savedInstanceState) {
  // … further layout init

Long power button press:

Now we come to my favorite hack: It is very simple but powerful.

Add the following snippet to your activity. It will surely prevent long press button.

public void onWindowFocusChanged(boolean hasFocus) {
  if(!hasFocus) {
	  // Close every kind of system dialog
    Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);

The idea is simple: in case any system dialog pops up, we kill it instantly by firing an ACTION_CLOSE_SYSTEM_DIALOG broadcast.

Disable the volume button

If necessary, you can easily deactivate the volume buttons by consuming both button calls. Just override dispatchKeyEvent in your Activity and handle the volume buttons:

private final List blockedKeys = new ArrayList(Arrays.asList(KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP));

public boolean dispatchKeyEvent(KeyEvent event) {
  if (blockedKeys.contains(event.getKeyCode())) {
    return true;
  } else {
    return super.dispatchKeyEvent(event);

Disable the home button and detect when new applications are opened

Since Android 4 there is no effective method to deactivate the home button. That is the reason why we need another little hack. In general the idea is to detect when a new application is in foreground and restart your activity immediately.

At first create a class called KioskService that extends Service and add the following snippet:

public class KioskService extends Service {

  private static final long INTERVAL = TimeUnit.SECONDS.toMillis(2); // periodic interval to check in seconds -> 2 seconds
  private static final String TAG = KioskService.class.getSimpleName();
  private static final String PREF_KIOSK_MODE = "pref_kiosk_mode";

  private Thread t = null;
  private Context ctx = null;
  private boolean running = false;

  public void onDestroy() {
    Log.i(TAG, "Stopping service 'KioskService'");
    running =false;

  public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "Starting service 'KioskService'");
    running = true;
    ctx = this;
    // start a thread that periodically checks if your app is in the foreground
    t = new Thread(new Runnable() {
      public void run() {
        do {
          try {
          } catch (InterruptedException e) {
            Log.i(TAG, "Thread interrupted: 'KioskService'");

    return Service.START_NOT_STICKY;

  private void handleKioskMode() {
    // is Kiosk Mode active? 
	  if(isKioskModeActive()) {
	    // is App in background?
      if(isInBackground()) {
        restoreApp(); // restore!

  private boolean isInBackground() {
    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    ComponentName componentInfo = taskInfo.get(0).topActivity;
    return (!ctx.getApplicationContext().getPackageName().equals(componentInfo.getPackageName()));

  private void restoreApp() {
    // Restart activity
    Intent i = new Intent(ctx, MyActivity.class);
  public boolean isKioskModeActive(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getBoolean(PREF_KIOSK_MODE, false);

  public IBinder onBind(Intent intent) {
    return null;

Add the following method in your AppContext class to start the service via application context creation.

public void onCreate() {
  instance = this;
  startKioskService();  // add this

private void startKioskService() { // ... and this method
  startService(new Intent(this, KioskService.class));

Last, add the service declaration and the permission for retrieving the foreground process to the manifest:

<service android:name=".KioskService" android:exported="false"/>

<uses-permission android:name="android.permission.GET_TASKS"/>

Basically, the thread checks every two seconds if your application is running in foreground. If not, the thread will immediately recreate your activity and your Android Kiosk is visible again.

Prevent screen dimming

It is also very easy to keep the screen bright as long as your app is visible (also forever). You only have to add the following flag to your root layout:


For example:

<RelativeLayout xmlns:android=""
  <!-- your layout -->

That’s it!


Developing a kiosk-based application is not the easiest part in Android development, but it is definitely possible to create a “robust” Kiosk Mode. The only disadvantage is the long list of (very) dirty hacks. If you do not have very specific requirements, it is a good choice to use an already existing Kiosk app.

Download example project

Update February 2017:

Prevent status bar expansion / disable status bar pull down

There is no option that disables the status bar expansion. However, it is possible to add an invisible layer on top of the status bar that catches every click/touch. That is just another workaround to make a real Android Kiosk happen:

public static void preventStatusBarExpansion(Context context) {
    WindowManager manager = ((WindowManager) context.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|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;

    int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    int result = 0;
    if (resId > 0) {
      result = context.getResources().getDimensionPixelSize(resId);
    } else {
      // Use Fallback size:
      result = 60; // 60px Fallback

    localLayoutParams.height = result;
    localLayoutParams.format = PixelFormat.TRANSPARENT;

    customViewGroup view = new CustomViewGroup(context);
    manager.addView(view, localLayoutParams);

public static class CustomViewGroup extends ViewGroup {
    public CustomViewGroup(Context context) {

    protected void onLayout(boolean changed, int l, int t, int r, int b) {

    public boolean onInterceptTouchEvent(MotionEvent ev) {
        // Intercepted touch!
        return true;

Necessary permission:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>