Android 4.2 for Kiosk Apps
One of the extremely annoying questions that appears from time to time in StackOverflow is “how do I block the HOME/BACK/RECENTS button”? Usually, this is in the context of people trying to write a “kiosk mode” app for a single-purpose device, where the only thing the user should do is use the “kiosk mode” app.
The good news is that as of Android 4.2, script-kiddie hacks for this are no longer necessary.
I was somewhat bummed by the switch to the status bar/navigation bar pattern for tablets in 4.2, as seen on the Nexus 10, due to the wasted screen space. But it does have one big advantage for kiosk apps: nothing else goes there (except a MENU affordance for legacy apps).
Hence, simply making your kiosk app be the home screen solves your navigation bar problems:
- Pressing HOME simply brings up your app
- Pressing BACK only navigates within your app
- Pressing RECENTS, while pointless, does not let anyone get anywhere other than your one-and-only app
- Pressing the MENU affordance, if there is one, just brings up your legacy options menu
By going with a
Fullscreen theme, access to the notification drawer
and things tucked away there (e.g., access to settings), goes away.
Now, this approach may not work for all Android tablets, as some device manufacturers could tinker with the navigation bar and add their own stuff there. But there will be a number of devices, Nexuses (Nexii?) among them, where your kiosk app will work just fine.
I hope that over time this will reduce the number of people trying to find security holes in Android to arrange to block access to navigation buttons, as if kiosk apps can do it, malware will surely follow. This way, only the home screen gets this “power”, and the user has to opt into making it their home screen, and can always revert to the stock home screen via a safe-mode reboot.
Interested in Jetpack Compose?
jetc.dev has a weekly newsletter of the latest articles, samples, and other details of Compose development!