Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
72 views
in Technique[技术] by (71.8m points)

toddler safe app on android

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, I succeeded in achieving this. However, now I have 2 problems:

  1. On 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.
  2. On ice cream sandwich (using 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

for android version 4 (API 14 and up) , it might be possible to use : getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

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 next 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 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) :

There are two ways to activate screen pinning:

Manually: Users can enable screen pinning in Settings > Security > Screen Pinning, and select the tasks they want to pin by touching the green pin icon in the recents screen. Programmatically: To activate screen pinning programmatically, call startLockTask() from your app. If the requesting app is not a device owner, the user is prompted for confirmation. A device owner app can call the setLockTaskPackages() method to enable apps to be pinnable without the user confirmation step.

What does it do? read further and see:

When task locking is active, the following behavior happens:

The status bar is blank, and user notifications and status information are hidden. The Home and Recent Apps buttons are hidden. Other apps cannot launch new activities. The current app can start new activities, as long as doing so does not create new tasks. When screen pinning is invoked by a device owner, the user remains locked to your app until the app calls stopLockTask(). If screen pinning is activity by another app that is not a device owner or by the user directly, the user can exit by holding both the Back and Recent buttons.

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.

Seems like the perfect thing for toddler safe app.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...