0

我想在启动某些应用程序之前启动一项安全活动。所以我认为我会使用 brodcastReceiver。检测此类活动的启动。我正在使用下面给出的代码来检测所有正在运行的 Activity 和正在运行的进程。我的问题是,一旦启动应用程序,我就会检测到它的执行,但我想检测使用此活动的意图,并在使用该活动之前请求许可。

setContentView(R.layout.main_list);
        context = this;
        // Find the ListView resource.

        ArrayList<String> planetList = new ArrayList<String>();
    //  planetList.addAll(Arrays.asList(planets));

        // Create ArrayAdapter using the planet list.
        listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow,
                planetList);

        // Set the ArrayAdapter as the ListView's adapter.

        int compteProcessusTues = 0;

        ActivityManager am = (ActivityManager) context
                .getSystemService(Activity.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> listeProcessus = am
                .getRunningAppProcesses();
        //the list of running process
        for (RunningAppProcessInfo processus : listeProcessus) {
            String packageName = processus.processName.split(":")[0];
            Log.d("List des process", packageName);
            if (!context.getPackageName().equals(packageName)
                    ) {
                am.restartPackage(packageName);
                compteProcessusTues++;
            }
        }
        // the list of running activity
        final List<RunningTaskInfo> recentTasks = am
                .getRunningTasks(Integer.MAX_VALUE);
        Log.d("liste des applications ", recentTasks.toString());

        for (int i = 0; i < recentTasks.size(); i++) {
            Log.d("============Executed app ======", recentTasks.get(i).topActivity.getShortClassName());
            listAdapter.add(recentTasks.get(i).baseActivity.toShortString());
        }
        mainListView.setAdapter(listAdapter);
4

0 回答 0