如何检测Small应用程序是否处于活动状态?
迷你app包名称 com.sony.nfx.app.plusone.calculator 是
在getRunningTasks中, 我相信你可以获得你已经开始的应用程序列表。
但是,mini-app不受此限制。
在getRunningTasks中, 无法获取您已启动的迷你应用程序的包名称。
我想检测迷你应用。 如果有任何好办法,请告诉我。
**
我不是简单地得到一个进程列表。我想发现这个事实 用户已开始操作。
**
谢谢。
索尼平板电脑S. Android 4.0.3
android 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 ///