禁用 Android 幼儿应用程序中的主页按钮?

发布于 2024-10-04 05:46:42 字数 656 浏览 3 评论 0原文

我开发了一个应用程序,它是一个图片幻灯片放映,当您点击它们时,每个图片都会播放声音。这就像一本适合2-4岁孩子的图画书。

问题是,由于 Android 不会让您捕获按下主页按钮并基本上禁用它,因此当父母将手机交给孩子与无人看管(勇敢的父母)一起玩时,孩子可能会无意中退出应用程序,然后拨打电话或否则调整手机。

目前还有另外两个应用程序针对此问题提供了伪修复。这些应用程序是 Toddler Lock 和 ToddlePhone。我尝试联系这些应用程序的开发人员寻求一些指导,但他们不愿意透露任何信息,如果可以的话,但是这里有人有任何建议吗?

看起来这两个其他应用程序的作用就像主屏幕替换应用程序。当您在这些应用程序上启用“儿童防护模式”时,系统会提示用户选择要执行操作的应用程序,选项包括“Launcher、LauncherPro 等”。加上幼儿应用程序。然后,您必须将幼儿应用程序设置为默认应用程序,瞧,手机被“锁定”,并且在“解锁”手机时只能使用组合键或触摸屏幕的四个角等来“解锁”。您的正常主屏幕应用程序默认已恢复。下次启用“儿童安全模式”时,您甚至不必将幼儿应用程序设置为默认应用程序。

我读到这两个应用程序在三星手机上存在问题,它们可能会导致无限的崩溃和重启循环,需要恢复出厂设置才能修复。显然,这不是解决问题的理想解决方案,但它看起来是目前唯一可用的解决方案。

有人对如何实施“儿童安全模式”有任何想法吗?

I've developed and app that is a slide show of pictures which each play a sound when you tap them. It's like a picture book for ages 2-4.

The problem is, since android won't let you capture a home button press and essentially disable it, when parents give the phone to their child to play with unattended (brave parent), the child can inadvertenly exit the app and then make calls or otherwise tweak the phone.

There are two other apps that currently have a psuedo fix for this issue. The apps are Toddler Lock and ToddlePhone. I've tried contacting the developers of these apps for some guidance but they haven't been willing to disclose anything, which if fine, but does anyone here have any suggestions?

It looks like both of those other apps are acting like a home screen replacement app. When you enable the "childproof mode" on those apps the user is prompted to chose and app for the action and the choices are "Launcher, LauncherPro, etc." plus the toddler app. You then have to make the toddler app the default and voila, the phone is "locked" and can only be "unlocked" using a key combination or touching the four corners of the screen, etc. when you "unlock" the phone. your normal home screen app default restored. You don't even have to make the toddler app the default the next time you enable the "childproof mode".

I have read that these two apps have problems with Samsung phones and they can cause an an infinite crash-and-restart-loop that requires a factory reset to fix. Obviously this is not the ideal solution to the problem but it looks like the only one availiable at this point.

Does anyone have any ideas on how to implement a "childproof mode"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

孤檠 2024-10-11 05:46:42

我需要让幼儿锁定新的应用程序,并且不想使用启动器。
这是我所做的,您可以在 https://play.google.com/store/apps/details?id=com.justforkids.animalsounds" rel="noreferrer">https:/ /play.google.com/store/apps/details?id=com.justforkids.animalsounds

  1. 激活锁定时,启动服务,并在锁定停用时停止
  2. 该服务 该服务会检查运行最多的应用,如果这不是我的 Activity,服务启动了我的 Activity
  3. 仍然存在一个问题,即当用户单击“主页”时,大约需要 6 秒才能再次启动我的 Activity。我认为这是 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" />

I needed to have toddler lock in a new app, and did not want to use a launcher.
Here is what I did, you can see the app at https://play.google.com/store/apps/details?id=com.justforkids.animalsounds

  1. When lock is activated, start a service, and stop it when lock is deactivated
  2. The service checks the top running app, and if it is not my activity, the service launches my activity
  3. There was still an issue that when the user clicks "home", it takes about 6 seconds before my activity is launched again. I assume this is a security feature in Android but not sure. To bypass this, when the service detects that another app is visible, it adds a top view (as an alert window) that covers the home screen for the few seconds it takes the app to re-launch.

For step 3, here are more details:

Create the overlay layout, for example file 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>

In your service to show or hide the overlay use:

  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);
  }

You will need the permission

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
陌伤浅笑 2024-10-11 05:46:42

我认为您关于更换主屏幕的看法是正确的。我知道幼儿锁不会覆盖主页按钮,因为(至少在我的 LG GW620 上)在幼儿锁中按住主页按钮会弹出 ALT-TAB 类型菜单 - 这往往会导致手机崩溃。

Android 开发网站上有一个主屏幕替换应用程序,带有源代码:

http://developer.android.com/resources/samples/Home/index.html

编辑:另外,ADW.Launcher:

http://code.google.com/p/adw-launcher-android/

I think you're right regarding the home screen replacement. Toddler Lock I know doesn't override the home button, because (at least on my LG GW620) while in Toddle Lock holding the home button brings up the ALT-TAB type menu - which then tends to crash the phone.

There is a home screen replacement app available, with source code, on the android dev site:

http://developer.android.com/resources/samples/Home/index.html

EDIT: also, ADW.Launcher:

http://code.google.com/p/adw-launcher-android/

短叹 2024-10-11 05:46:42
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 中不起作用,并且会导致应用程序崩溃

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;
        }
       }

Edit:
This works in all older version of android. But will not work in ICS and jelly bean and will give you crash in app

〆凄凉。 2024-10-11 05:46:42

对于 4.0 及更高版本,您可以避免 Android 安全限制并将您的应用程序设置为启动器。将其添加到您的清单文件中:

<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>

For versions 4.0 and above you can avoid Android security restrictions and set your app as a launcher. Add this to your manifest file:

<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>
墨小沫ゞ 2024-10-11 05:46:42

我使用以下代码替换了默认主页启动器:

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);

I replaced the Default Home launcher using the following code:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文