如何通过我在android中的应用程序检测用户点击/启动的应用程序

时间:2013-02-05 07:30:37

标签: android android-intent

我需要知道是否有任何接收器来检测用户通过我自己的应用程序点击或启动/启动的应用程序

2 个答案:

答案 0 :(得分:1)

我认为你可以使用logcat并分析它的输出。

在所有类似的程序中,我发现了这个权限:

android.permission.READ_LOGS

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

使用以下代码:

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

并且不要忘记它对android清单的许可。

<强>更新: 通过跟踪 Logcat 找到启动的应用程序。只需使用 info -I 日志跟踪 ActivityManager 标记。

来自adb shell命令是,

adb logcat ActivityManager:I *:S

从您的应用程序代码

logcat ActivityManager:I *:S

在Logcat中,您可以找到类似

的行
I/ActivityManager(  585): Starting activity: Intent { action=android.intent.action...}

何时启动任何应用程序。

它是logcat输出,显示消息与优先级“I”和标记“ActivityManager”相关:

只需在应用程序的清单文件中添加权限

即可

android.permission.READ_LOGS

答案 1 :(得分:0)

从Android 4.1开始,这个版本已被弃用了一个应用程序只能使用android.permission.READ_LOGS访问自己的日志