如何接收应用程序的启动?

时间:2013-07-24 08:42:57

标签: android android-broadcast

我想在启动某个应用程序之前启动安全活动。所以我认为我将使用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);

0 个答案:

没有答案