Lock Your Device to One App

Learn how to enable App Pinning (Kiosk Mode) on Android to lock your device to a single application for a more controlled previewing environment.

App Pinning is currently only available on Android devices

App pinning, also known as Kiosk Mode, is a feature that restricts users to a single app, preventing access to other applications, settings, or the home screen. This is especially useful in scenarios where you want to restrict access to other parts of the device.

In this guide we will cover how you can enable app pinning for the current running application using our JavaScript SDK and adbShellCommand functionality.

JavaScript SDK Setup

Before enabling App Pinning, you need to ensure that the Appetize JavaScript SDK is properly set up in your project. The SDK allows you to control various aspects of the device, including sending ADB shell commands.

Follow our Getting Started steps to set up the JavaScript SDK.

Enabling App Pinning

Once your SDK setup is complete, you can enable App Pinning by running the following function after the session has started:

Pin Running Application
async function pinRunningApp(session) {
    // Apply app pinning to the currently launched application
    const command = 'taskId=\$(am stack list | grep -E -o \"taskId=[0-9]+: $PACKAGE\" | grep -E -o \"[0-9]+\"); am task lock \$taskId';
    await session.adbShellCommand(command);
}

Disable System Toasts (Optional)

You can choose to disable toast notifications during the session, such as the confirmation message indicating that your app has been pinned. This is optional and can help reduce distractions or clutter.

async function disableToastMessages(session) {
    await session.adbShellCommand('appops set com.android.systemui TOAST_WINDOW deny');
}

Last updated