机器人,检测当其他应用程序正在启动 [英] Android, Detect when other apps are launched

查看:208
本文介绍了机器人,检测当其他应用程序正在启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜 我想开发一个应用程序,prevents无法到达指定的应用程序,没有密码的用户。该方案是...

Hi I'm trying to develop an app that prevents a user from getting to a specified app without a password. The scenario is...

  1. 在用户点击电子邮件应用程序(例如)
  2. 在我的应用程序检测到启动一个应用程序
  3. 在我的应用程序确认这是电子邮件应用程序
  4. 在我的应用程序打开查看过顶,要求输入密码
  5. 在用户输入密码,如果正确的话,我的应用程序消失,留在上面的电子邮件应用程序

我确定做它的其余部分,只是其中的一部分2我百思不得其解,经过多天读了广播意图等,并试图在我的试验项目监听android.intent.action.MAIN等我似乎无法启动一个应用程序比我其他的时候被发现。

I'm ok doing the rest of it, just part 2 is puzzling me, and after many days reading up on Broadcast Intents etc and trying to listen for "android.intent.action.MAIN" etc in my trial projects I can't seem to detect when an app other than mine is started.

谁能帮助?我要对正确的方式,在寻找广播的意图,开始新的应用程序,或者我应该去阅读系统日志中的新意图,或做一些在本土code?

Can anyone help? Am I going about it the right way, in looking for new apps broadcasting an intent to start, or should I be reading the system log for new intents, or doing something in native code?

任何指针会有所帮助,即使你不能完全回答这个问题我就可以做一些更多的研究。多谢。伊恩

Any pointers would help, even if you can't answer it fully I'll be able to do some more research. Thanks a lot. Ian

推荐答案

我觉得我们可以使用的logcat 并分析它的输出。

I think we can use logcat and analyze it's output.

在所有类似的方案,我发现这个权限:

In all similar programs I have found this permission :

android.permission.READ_LOGS

这意味着所有的人使用它,但它似乎在程序启动后,我们的程序(应用程序保护)将启动,并把前面。

It means all of them use it but it seems the program starts and after that our program (app protector) will start and bring front.

使用低于code:

try
    {
        Process mLogcatProc = null;
        BufferedReader reader = null;
        mLogcatProc = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});

        reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));

        String line;
        final StringBuilder log = new StringBuilder();
        String separator = System.getProperty("line.separator"); 

        while ((line = reader.readLine()) != null)
        {
            log.append(line);
            log.append(separator);
        }
        String w = log.toString();
        Toast.makeText(getApplicationContext(),w, Toast.LENGTH_LONG).show();
    }
    catch (Exception e) 
    {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }

和不要忘记添加它的清单文件的权限。

And do not forget to add it's permission in Manifest file.

这篇关于机器人,检测当其他应用程序正在启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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