Implementing Kiosk Mode in Android - Part 2
In Part 1 of this article we talked about how to implement Kiosk Mode using Android’s built-in Car Mode. But there were two problems with the Home key that Car Mode could not fix:
Our Car Mode application will never see the Home key. Pressing the Home key will always take us back to our app’s main Activity, even if that’s not what we want.
If we long-press the Home key, Android will show us a list of recently-run apps that we can switch to.
To fix these problems, we need modify Android itself. Here is the patch for Android version 4.1.2_r1: home_key_not_special.diff
After applying this patch to Android, we just need to add this to our app’s manifest,
<meta-data android:name="HOME_KEY_NOT_SPECIAL" android:value="true" />
and the Home will be treated just like a normal key.
Another feature that we want for Kiosk Mode is the ability to run our app when Android boots instead of the regular Home app (usually called Launcher). To implement this, we need to apply this patch to Android: run_at_boot.diff
Then we add this to the section of our app’s manifest:
<span><category android:name="RUN_AT_BOOT" /> </span>
Now our app will be run at boot time instead of the Home app.
Updated Demo App
The result of these changes is an updated version of our demo app: CarModeDemo2.zip that fixes the Home key problems. Please contact us if you need any assistance with your Android development or porting needs.
Update: Google is adding this capability to Android L, and calling it Task Locking. More information to come...