Kiosk mode in Android
Categories:
Mastering Android Kiosk Mode: Dedicated Device Management

Explore Android Kiosk Mode, a powerful feature for dedicating devices to a single application or a restricted set of applications, ideal for business, education, and public use cases. Learn how to implement and manage it effectively.
Android Kiosk Mode transforms a standard Android device into a dedicated, single-purpose machine. This is crucial for scenarios where devices are used for specific tasks, such as point-of-sale systems, digital signage, educational tools, or information kiosks. By locking down the device to one or a few applications, Kiosk Mode prevents unauthorized access to other apps, settings, or the device's core functionalities, ensuring a focused and secure user experience.
Understanding Android Kiosk Mode
Kiosk Mode is primarily achieved through Android's Device Policy Controller (DPC) APIs, which allow for comprehensive device management. When a device is provisioned as a Device Owner, a DPC application can enforce policies that restrict user access, manage applications, and control hardware features. This level of control is essential for maintaining the integrity and security of dedicated devices.
flowchart TD A[Android Device] --> B{Provision as Device Owner?} B -- Yes --> C[Install DPC App] C --> D[Set Kiosk Policies] D --> E[Lock Device to App(s)] E --> F[Dedicated Kiosk Mode] B -- No --> G[Standard Android Device]
Flowchart illustrating the setup process for Android Kiosk Mode.
Key Features and Capabilities
Implementing Kiosk Mode involves leveraging several Android APIs to achieve the desired lockdown. These include setting a specific app as the home screen, disabling status bar notifications, preventing access to recent apps, and controlling hardware buttons. The level of restriction can be tailored to the specific use case, from a single-app lockdown to a multi-app environment with controlled access.
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
public class KioskModeHelper {
private DevicePolicyManager dpm;
private ComponentName adminComponent;
public KioskModeHelper(Context context) {
dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
adminComponent = new ComponentName(context, MyDeviceAdminReceiver.class);
}
public void enableKioskMode(String packageName) {
if (dpm.isDeviceOwnerApp(adminComponent.getPackageName())) {
// Set the app as the lock task mode (kiosk mode) package
String[] packages = {packageName};
dpm.setLockTaskPackages(adminComponent, packages);
// Start lock task mode
// This typically happens from within the app's activity
// activity.startLockTask();
// Disable keyguard (lock screen)
dpm.setKeyguardDisabled(adminComponent, true);
// Disable status bar and notifications
dpm.setStatusBarDisabled(adminComponent, true);
// Other restrictions can be applied here
// e.g., dpm.addUserRestriction(adminComponent, UserManager.DISALLOW_FACTORY_RESET);
}
}
public void disableKioskMode() {
if (dpm.isDeviceOwnerApp(adminComponent.getPackageName())) {
// Stop lock task mode
// activity.stopLockTask();
// Re-enable keyguard
dpm.setKeyguardDisabled(adminComponent, false);
// Re-enable status bar
dpm.setStatusBarDisabled(adminComponent, false);
// Clear lock task packages
dpm.setLockTaskPackages(adminComponent, new String[]{});
}
}
}
Example Java code snippet for enabling and disabling Kiosk Mode using DevicePolicyManager.
Implementing Kiosk Mode: A Step-by-Step Guide
Setting up Kiosk Mode involves several critical steps, from preparing your application to provisioning the device as a Device Owner. This process ensures that your application has the necessary permissions to control device behavior and maintain the kiosk state.
1. Prepare Your Application
Develop your Android application to be Kiosk Mode compatible. This includes handling lifecycle events when entering and exiting lock task mode, ensuring your app can restart if crashed, and providing a way to exit Kiosk Mode (e.g., via a hidden gesture or admin password).
2. Declare Device Admin Receiver
Create a DeviceAdminReceiver
class in your application and declare it in your AndroidManifest.xml
. This receiver will handle administrative events and is crucial for your app to become a Device Owner.
3. Provision as Device Owner
This is the most critical step. A device can only have one Device Owner. This is typically done during the initial device setup (out-of-box experience) using NFC, QR code, or a specific ADB command. For example, adb shell dpm set-device-owner com.yourpackage/.MyDeviceAdminReceiver
.
4. Enable Lock Task Mode
Once your app is the Device Owner, use DevicePolicyManager.setLockTaskPackages()
to specify which applications (usually just your own) are allowed in lock task mode. Then, from within your app's activity, call startLockTask()
to enter Kiosk Mode.
5. Apply Device Restrictions
Use DevicePolicyManager
to apply various restrictions, such as disabling the status bar (setStatusBarDisabled
), preventing factory reset (addUserRestriction(UserManager.DISALLOW_FACTORY_RESET)
), and disabling keyguard (setKeyguardDisabled
).