Ive been working on this for quite some time but can't seem to find a solution.
I have an android tablet that is intended for use in a proprietary application. We need to lock down the tablet so it can only run the app(and select few others). Im aware of "Kiosk" mode but I need the user to still have access to the back and home buttons(home goes back to our app)
Primarily the reason I need the user to still have access to the back and home buttons is so they can get back to my app after launching say... wifi settings.
My application has a thread that is always running even when not in the foreground for data handling and such. So my first idea was... lets detect what application is in the foreground and if it isn't my application or a small list of allowed(like wifi settings) then kill the app and bring my app to the foreground. But no matter what I try it doesn't seem to work...
First I tried to just simulate the home button(my app is linked to the home button) This doesn't work once my app is the only home button option.
Ive tried using android.os.Process.killProcess to kill any application that is in the foreground... this only works with very few apps.
Ive also tried re-launching the app using an intent but that doesn't work either.
I understand that this is mostly due to the android system trying to keep malicious apps from taking control of the device, this app will not be distributed on any market.
Impossible, and extremely misguided to even attempt. As you mention, Android 5.0 introduces a legitimate kiosk mode (called "screen pinning" or "task locking") which allows a single app to take over the device. I don't think there's any way to launch third-party activities as part of your locked task. Before 5.0, the ugly hack to simulate kiosk mode was to constantly poll the list of foreground apps, and if the top app wasn't on your whitelist, fire off your app's launcher intent to bring your app to the foreground. Google keeps coming up with ways to prevent this from working; for example, sometime in 4.x they made it so you can swipe down the task bar over any "full screen" app, which will not trigger your app realizing it's not in the foreground. From there it's pretty easy to kill your whole app. They completely break this hack in 5.0, because each app only sees itself in the list of foreground apps.
You can't even guarantee that, especially if you are explicitly creating a
Thread
instead of using an Android component like anIntentService
. Android can destroy your components whenever they are not in the foreground, and if the app has no components left, it can kill the entire process. So anyThread
you've created may be abruptly killed, with no built-in way to restart it when your app returns to the foreground. There is almost never a legitimate reason to explicitly create aThread
in Android.