I have an app, that should be toddler safe. Meaning that, it blocks any single key touch, yet handles long pressing for exiting the app.
This is so that, the toddler will be safe from doing (too) nasty things while playing.
Up to version 2.3.4 (Gingerbread), I succeeded in achieving this.
However, now I have two problems:
-
On Android 3 (Honeycomb), I have the status bar notifications which can be pressed on. Also, I have the switch-windows key which can be pressed. The only thing I succeeded with it is to dim the status bar.
-
On Android 4.0 (Ice Cream Sandwich) (using the emulator, I still don’t have a real device with this version), when calling the next code, I get an exception which cannot even be caught.
The exception:
java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
The code:
@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
super.onAttachedToWindow();
}
What can I do?
For Android version 4 (API 14 and up), it might be possible to use:
However, on the emulator, it doesn’t block the home button, so it’s kinda useless.
I still don’t know if it works fine on real devices.
Maybe it’s possible to use the following workaround:
Set the app as the default home screen app.
If the home button was pressed while the application was active, capture it and do nothing.
If the home button was pressed while the application was on the background (or closed), open the previously selected default home app.
Alternatively, I could ask the user to set the default home launcher app as mine for each time it is started, and reset it again (either to the previous one, or total reset) after it is closed.
Is it possible? If so, how?
Since Android 5.0 (Lollipop) (version 5.0 which is API 21), there is a way of screen-pinning, and this can be turned on by the user or the app (link here):
What does it do? Read further and see:
When task locking is active, the following behavior happens:
Not only that, but according to this post, you can also toggle this without user-confirmation, and exiting this special state would be under your app’s logic.
It seems like the perfect thing for toddler safe app.