How do we enable kiosk mode (Lock Task Mode) in React Native CLI application?


I want to enable kiosk mode (Lock Task Mode) in a React Native CLI application. Most of the articles I’ve found are around 6 years old, so I was wondering if there’s a more recent or recommended approach. Any help would be appreciated. Thanks in advance.

1
Feb 25 at 10:10 AM
User AvatarTalha Noman
#android#react-native#mobile-development#kiosk-mode

Accepted Answer

React Native does not support Android Kiosk (Lock Task) mode directly,
You must enable it using native Android code

1. Start Lock Task Mode in MainActivity

@Override
protected void onResume() {
  super.onResume();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    startLockTask();
  }
}

This enables kiosk mode when the app is in the foreground.

2. Control from React Native(Optional)

Create a native module and call :

activity.startLockTask(); // To enable
activity.stopLockTask();  // To disable

3. Use Device Owner for full kiosk(Recommended)

Without a device owner, Android shows a confirmation dialog, and users can exit.

adb shell dpm set-device-owner com.yourapp/.DeviceAdminReceiver


User Avataramboji alur
Feb 25 at 10:24 AM
0