Android 安卓锁应用程序

Android 安卓锁应用程序,android,Android,我是新来的,我一直在寻找问题来帮助我,但我没有明确的答案 我需要制作一个应用程序来阻止手机上的其他应用程序。 我在市场上见过好几种,但我想做一种。 有没有办法知道用户何时尝试打开应用程序并提出活动?(输入密码) 我尝试使用FileObserver,但只适用于文件和目录(显然)。 我可以在启动之前创建一个侦听器来捕获其他应用程序的意图吗 我为我的英语道歉,我感谢你的帮助 不,如果没有某种黑客攻击,您无法知道何时启动另一个应用程序。 这是因为不会广播应用程序启动 您可以做的是创建一个以固定间隔(比如

我是新来的,我一直在寻找问题来帮助我,但我没有明确的答案

我需要制作一个应用程序来阻止手机上的其他应用程序。 我在市场上见过好几种,但我想做一种。 有没有办法知道用户何时尝试打开应用程序并提出活动?(输入密码)

我尝试使用FileObserver,但只适用于文件和目录(显然)。 我可以在启动之前创建一个侦听器来捕获其他应用程序的意图吗


我为我的英语道歉,我感谢你的帮助

不,如果没有某种黑客攻击,您无法知道何时启动另一个应用程序。 这是因为不会广播应用程序启动

您可以做的是创建一个以固定间隔(比如1000毫秒)运行的服务,以检查前端的非系统应用程序。杀死该应用程序并从服务弹出密码输入框。如果密码正确,请重新启动该应用程序

下面是一些代码示例

    timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {   
           List<RunningAppProcessInfo> appProcesses= activityManager.getRunningAppProcesses();
        for (RunningAppProcessInfo appProcess : appProcesses) {
            try {
            if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            if (!lastFrontAppPkg.equals((String) appProcess.pkgList[0])) {
            apkInfo = ApkInfo.getInfoFromPackageName(appProcess.pkgList[0], mContext);
                if (apkInfo == null || (apkInfo.getP().applicationInfo.flags && ApplicationInfo.FLAG_SYSTEM) == 1) {
                  // System app                                             continue;
                        } else if (((apkInfo.getP().versionName == null)) || (apkInfo.getP().requestedPermissions == null)) {
                    //Application that comes preloaded with the device
                        continue;
                     } else {
                     lastFrontAppPkg = (String) appProcess.pkgList[0];
                     }
    //kill the app
    //Here do the pupop with password to launch the lastFrontAppPkg if the pass is correct
                         }
                      }
                   }
                 } catch (Exception e) {
                  //e.printStackTrace();
                }
               }                        
             }
           }, 0, 1000);

有一种方法可以做到这一点。您可以知道应用程序何时启动。 您可以使用packagemanager类获取有关任何已安装和inbuld应用程序的所有信息。并使用下面的代码了解该应用程序是如何启动的

           @Override
    public void run() {  Log.i("test","detector run");
        try {
            Process process;
            process = Runtime.getRuntime().exec(ClearLogCatCommand);
            process = Runtime.getRuntime().exec(LogCatCommand);
            br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            // Check if it matches the pattern
            while(((line=br.readLine()) != null) && !this.isInterrupted()){

                Log.d("Detector", "RUN"+line);

                // Ignore launchers
                if (line.contains("cat=[" + Intent.CATEGORY_HOME + "]")) continue;

                Matcher m = ActivityNamePattern.matcher(line);
                if (!m.find()) continue;
                if (m.groupCount()<2){
                    // Log.d("Detector", "Unknown problem while matching logcat output. Might be SDK version?");
                    continue;
                }

                if (mListener!=null) mListener.onActivityStarting(m.group(1), m.group(2));

                Log.i("Detector", "Found activity launching: " + m.group(1) + "  /   " + m.group(2));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
@覆盖
public void run(){Log.i(“测试”、“检测器运行”);
试一试{
工艺过程;
process=Runtime.getRuntime().exec(ClearLogCatCommand);
process=Runtime.getRuntime().exec(LogCatCommand);
br=新的BufferedReader(新的InputStreamReader(process.getInputStream());
弦线;
//检查它是否与模式匹配
而(((line=br.readLine())!=null)和&!this.isInterrupted()){
日志d(“探测器”、“运行”+线路);
//忽略发射器
如果(行包含(“cat=[”+Intent.CATEGORY_HOME+“])继续;
Matcher m=ActivityNamePattern.Matcher(行);
如果(!m.find())继续;

如果(m.groupCount()您现在可以使用AccessibilityService,它允许您找出哪个活动位于顶部

在AccessibilityService类中:

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        ComponentName componentName = new ComponentName(
                event.getPackageName().toString(),
                event.getClassName().toString()
        );

        ActivityInfo activityInfo = tryGetActivity(componentName);
        boolean isActivity = activityInfo != null;
        if (isActivity) {
            Log.i("CurrentActivity", componentName.flattenToShortString());
        }
    }
}
你必须在手机的设置中打开无障碍功能,这可以通过进入“设置>无障碍功能>服务>你的应用程序”来完成。你还必须在清单中添加一些权限。许多信息可以在Android开发者网站上找到:


希望这能有所帮助!

谢谢Weakwire!这真的很有用!我需要做一些工作来完成我想要的,但这是一个总体想法!谢谢!这是一个不完整的方法,因为对于“//杀死应用程序”没有有效的解决方案。若要杀死另一个应用程序,您的应用程序必须在前台运行。然后,您可以用其包名杀死该应用程序。请查看@weakwire…感谢您的回答。我想知道另一种重复运行代码的方法,而不是计时器,因为在我多次检查该代码后,计时器会被系统破坏。Thanks。每秒检查一次的服务将在几个小时内耗尽你的电池。制作一个启动器/家庭应用程序不是更好吗?你是对的!但这不是我想要的。谢谢你的回答!我正在尝试使用此代码,但我有点做错了。请你提供更多代码来使用它。谢谢。屏幕截图:@anujsharma它在jelly及以上版本上的工作……为了你的好主意,我已经测试了它,我的代码在安卓Lthanks中也能完美工作。你能对
tryGetActivity(componentName)
方法做更多解释吗?
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        ComponentName componentName = new ComponentName(
                event.getPackageName().toString(),
                event.getClassName().toString()
        );

        ActivityInfo activityInfo = tryGetActivity(componentName);
        boolean isActivity = activityInfo != null;
        if (isActivity) {
            Log.i("CurrentActivity", componentName.flattenToShortString());
        }
    }
}