0

如何检测小应用程序是否处于活动状态?

小程序包名 com.sony.nfx.app.plusone.calculator 就是。

在getRunningTasks中,相信你可以得到你已经启动的应用列表。

但是,小程序不受此限制。

在getRunningTasks中,一直无法获取到你已经启动的小程序的包名。

我想检测迷你应用程序。如果有什么好的方法,请告诉我。

**

我不是简单地获取进程列表。我想检测用户已经开始操作的事实。

**

谢谢你。

索尼平板电脑 S 安卓 4.0.3

安卓java代码

public void run_task_log(){


       ArrayList<String> appList = new ArrayList<String>();
        ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);


        List<RunningAppProcessInfo> processList = activityManager.getRunningAppProcesses();
        for(RunningAppProcessInfo process : processList) {
            //Log.i(TAG,"pid:"+process.pid);
            //Log.i(TAG,"processName:"+process.processName);
            appList.add(   (String) "" + process.pid + ":" +process.processName);
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, appList);
        setListAdapter(adapter);








        List<RunningTaskInfo> taskList = activityManager.getRunningTasks(10);
        for(RunningTaskInfo task : taskList) {
            Log.d("ActivityManager","task.topActivity.getPackageName():"+task.topActivity.getPackageName());
        }
        List<RunningServiceInfo> serviceList = activityManager.getRunningServices(30);
        for(RunningServiceInfo serv : serviceList) {
            Log.d("ActivityManager","PID:"+serv.pid+":serv.getPackageName():"+serv.service.getPackageName());
            Log.d("ActivityManager","PID:"+serv.pid+":serv.clientPackage():"+serv.clientPackage);
        }




        PackageManager packageManager = getPackageManager();
        ActivityManager activityManager1 = ((ActivityManager) getSystemService(ACTIVITY_SERVICE));
        List<RunningTaskInfo> runningTask = activityManager1.getRunningTasks(100);
        ArrayList<CharSequence> activityNameList = new ArrayList<CharSequence>();
        if (runningTask != null) {
            for (RunningTaskInfo task : runningTask) {
                try {
                    Log.d("ActivityManager","packageManager.getApplicationLabel():"+packageManager.getApplicationLabel(packageManager.getApplicationInfo(task.topActivity.getPackageName(), 0)));
                } catch (NameNotFoundException e) {
                    Log.e("ERROR", e.toString());
                }
            }
        }




        ActivityManager activityManager2 = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE);
        String className = activityManager.getRunningTasks(3).get(0).topActivity.getClassName();
        Log.d("ActivityManager","className:"+className);


}

Logcat 日志

    12-11 16:53:36.360: D/T2MDMService(3775): ////// ID Service Timer Start ///
12-11 16:53:36.370: D/ActivityManager(3775): task.topActivity.getPackageName():com.sony.nfx.app.launcher2
12-11 16:53:36.370: D/ActivityManager(3775): task.topActivity.getPackageName():com.anetm.www.apprunlist
12-11 16:53:36.380: D/ActivityManager(3775): PID:434:serv.getPackageName():com.android.smspush
12-11 16:53:36.380: D/ActivityManager(3775): PID:434:serv.clientPackage():null
12-11 16:53:36.380: D/ActivityManager(3775): PID:2996:serv.getPackageName():com.sony.nfx.app.plusone.calculator
12-11 16:53:36.380: D/ActivityManager(3775): PID:2996:serv.clientPackage():null
12-11 16:53:36.380: D/ActivityManager(3775): PID:3174:serv.getPackageName():com.android.providers.media
12-11 16:53:36.380: D/ActivityManager(3775): PID:3174:serv.clientPackage():null
12-11 16:53:36.380: D/ActivityManager(3775): PID:3534:serv.getPackageName():com.sony.nfx.hwmonitorservice
12-11 16:53:36.390: D/ActivityManager(3775): PID:3534:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.getPackageName():com.google.android.location
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:0:serv.getPackageName():com.google.android.talk
12-11 16:53:36.390: D/ActivityManager(3775): PID:0:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:3522:serv.getPackageName():com.sony.nfx.app.wappushdbinit
12-11 16:53:36.390: D/ActivityManager(3775): PID:3522:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:249:serv.getPackageName():com.android.systemui
12-11 16:53:36.390: D/ActivityManager(3775): PID:249:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:3508:serv.getPackageName():com.sony.automagic.blservice
12-11 16:53:36.390: D/ActivityManager(3775): PID:3508:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.getPackageName():com.google.android.location
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:2984:serv.getPackageName():com.sony.smallapp.plusoneservice
12-11 16:53:36.390: D/ActivityManager(3775): PID:2984:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:328:serv.getPackageName():com.sony.nfx.inputmethod
12-11 16:53:36.400: D/ActivityManager(3775): PID:328:serv.clientPackage():android
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.getPackageName():com.android.stk
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:167:serv.getPackageName():com.google.android.backup
12-11 16:53:36.400: D/ActivityManager(3775): PID:167:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.getPackageName():com.android.phone
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.getPackageName():com.mbm.mbmservice
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:249:serv.getPackageName():com.android.systemui
12-11 16:53:36.400: D/ActivityManager(3775): PID:249:serv.clientPackage():android
12-11 16:53:36.400: D/ActivityManager(3775): PID:3495:serv.getPackageName():com.sony.automagic.ui
12-11 16:53:36.400: D/ActivityManager(3775): PID:3495:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:313:serv.getPackageName():com.google.android.gsf
12-11 16:53:36.400: D/ActivityManager(3775): PID:313:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): packageManager.getApplicationLabel():ホーム
12-11 16:53:36.400: D/ActivityManager(3775): packageManager.getApplicationLabel():AppRunList
12-11 16:53:36.410: D/ActivityManager(3775): className:com.android.launcher2.Launcher
12-11 16:53:36.410: D/T2MDMService(3775): ////// ID Service Timer End ///
4

0 回答 0