如何禁用儿童场所的应用home键LIK? [英] How to disable home button lik in Kids Place application?

查看:133
本文介绍了如何禁用儿童场所的应用home键LIK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个家长控制应用程序,所以我需要阻止home键,当home键用户点击,他将被重定向到我的应用程序的其它活动。
我用这两条线在AndroidManifest

I am trying to develop a parental control application, so I need to block home button, when user clicks on home button he is redirected to another activity of my application. I used these two lines in AndroidManifest

<category android:name="android.intent.category.HOME"/>    
<category android:name="android.intent.category.DEFAULT" />

不过,我想重定向用户没有给他申请和启动之间的选择。

But, I want to redirect user without giving him a choice between application and launcher.

任何一个可以帮助我吗?

Any one can help me?

推荐答案

您可以使用的服务,如:

You can use service such as:

try {
    Intent intent1 = new Intent(thisActivity, Reciver.class);
    PendingIntent sender = PendingIntent.getBroadcast(thisActivity, 2, intent1, 0);
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    long l = new Date().getTime();
//You can increase/decrease time "1200" in millisecond
    am.setRepeating(AlarmManager.RTC_WAKEUP, l, 1200, sender);
} catch (Exception e) {
}

创建类 Reciver

public class Reciver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //call check Running Applications method.
        MainActivity.checkRunningApplications();
    }
}

在活动添加功能 checkRunningApplications()

public static void checkRunningApplications() {
ActivityManager am1 = (ActivityManager) thisActivity.getSystemService(Activity.ACTIVITY_SERVICE);
            String packageName = am1.getRunningTasks(1).get(0).topActivity.getPackageName();

if(packageName!="Your App Package Name"){
       //open Anthor Activity
   }
else{
       //Nothing
  }
}

这篇关于如何禁用儿童场所的应用home键LIK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆