禁用Android Toddler应用程序中的主页按钮?
-
28-09-2019 - |
题
我已经开发了一个幻灯片的幻灯片,当您点击它们时,每个图片都会播放声音。这就像一本年龄在2-4岁之间的图画书。
问题是,由于Android不能让您捕获一个主按钮按下并基本上禁用它,当父母给孩子打电话给孩子与无人值守(勇敢的父母)一起玩时,孩子可以inadvertentertentertentertentertentertentertentertentertentertentertentertentertentertenterten the应用程序,然后打电话或打电话或否则调整电话。
目前还有其他两个应用程序对此问题进行了修复。这些应用程序是幼儿锁和Toddlephone。我已经尝试与这些应用程序的开发人员联系以获取一些指导,但是他们不愿意透露任何东西,如果有的话,但是这里有人有任何建议吗?
看起来其他两个应用都像主屏幕更换应用程序一样。当您在这些应用程序上启用“儿童防护模式”时,提示用户选择和应用程序进行操作,并且选择是“启动器,启动器等”。加上幼儿应用程序。然后,您必须使幼儿应用程序默认,瞧,手机被“锁定”,只能使用键组合或触摸屏幕的四个角,等等。当您“解锁”手机时。您的普通主屏幕应用程序默认情况已恢复。下次启用“儿童防护模式”时,您甚至不必将幼儿应用程序作为默认值。
我已经读到这两个应用程序在三星手机上存在问题,它们可能会导致无限的崩溃和重新设备,该环路需要出厂设置才能修复。显然,这不是解决问题的理想解决方案,但是目前看来唯一可用的方法。
有人对如何实施“防儿童模式”有任何想法吗?
解决方案
我认为您对主屏幕更换是正确的。我知道的幼儿锁不会覆盖主页按钮,因为(至少在我的LG GW620上)在托住锁定按钮的托德锁时,请提出alt -tab类型的菜单 - 然后倾向于崩溃手机。
Android Dev网站上有一个带有源代码的主屏幕替换应用程序:
http://developer.android.com/resources/samples/home/index.html
编辑:另外,adw.launcher:
其他提示
我需要在一个新应用程序中将幼儿锁定,并且不想使用启动器。这是我所做的,您可以在 https://play.google.com/store/apps/details?id=com.justforkids.animalsounds
- 激活锁定后,开始服务,并在停用锁定时将其停止
- 该服务检查顶部运行应用程序,如果不是我的活动,则该服务将启动我的活动
- 仍然存在一个问题,当用户单击“主页”时,我的活动再次启动大约需要6秒钟。我认为这是Android中的安全功能,但不确定。为了绕过这一点,当服务检测到另一个应用程序可见时,它添加了顶部视图(作为警报窗口),该视图覆盖了主屏幕,需要该应用程序重新发布。
对于第3步,以下是更多详细信息:
创建覆盖布局,例如文件locked_overlay.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d0000000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="@string/app_name"
android:textColor="#fff"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Locked mode is on"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
</FrameLayout>
在您的服务中显示或隐藏覆盖层的使用:
private View lockedOverlay = null;
private void hideLockedOverlay() {
if (lockedOverlay != null) {
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.removeView(lockedOverlay);
lockedOverlay = null;
}
}
private void showLockedOverlay() {
if (lockedOverlay != null) {
return;
}
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams viewLayoutParams = new WindowManager.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
viewLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
LayoutInflater inflater = LayoutInflater.from(this);
lockedOverlay = inflater.inflate(R.layout.locked_overlay, null);
windowManager.addView(lockedOverlay, viewLayoutParams);
}
您将需要许可
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Add in to your Main Activity
@Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
And Override Key down event
@Override
public boolean onKeyDown(int iKeyCode, KeyEvent event)
{
if(iKeyCode == KeyEvent.KEYCODE_BACK || iKeyCode == KeyEvent.KEYCODE_HOME)
{
return true;
}
}
编辑:这在所有旧版本的Android中都起作用。但不会在ICS和Jelly Bean中起作用,并且会让您在应用程序中崩溃
我使用以下代码替换了默认的家庭启动器:
Intent selector = new Intent("android.intent.action.MAIN");
selector.addCategory("android.intent.category.HOME");
selector.setComponent(new ComponentName("android","com.android.internal.app.ResolverActivity"));
startActivity(selector);
对于版本4.0及更高版本,您可以避免使用Android Security限制,并将应用程序设置为启动器。将其添加到您的清单文件中:
<uses-permission android:name="android.permission.GET_TASKS" />
<activity
android:launchMode="singleInstance"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>