例如,我在我的AVD背景中运行“音乐”和“语音记录器”。我想制作一个可以显示名称“音乐,录音机”的AlertDialog。谁能给我一些代码?谢谢。
答案 0 :(得分:0)
您可以使用以下行列出所有流程:
ActivityManager localActivityManager = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
List RunningServiceInfo services = localActivityManager .getRunningServices(100);
从RunningServiceInfo您可以获得有关此过程的详细信息。 另一种方法是使用getRunningAppProcesses。
答案 1 :(得分:0)
这可能对你有帮助......
public static HashSet<String> getRunningApps(Context context) {
final HashSet<String> hashSet = new HashSet<String>();
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
final PackageManager packageManager = context.getPackageManager();
List<RunningTaskInfo> runningTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (RunningTaskInfo runningTaskInfo : runningTasks) {
String packageName = runningTaskInfo.baseActivity.getPackageName();
try {
String appName = packageManager.getApplicationInfo(packageName, 0).loadLabel(packageManager).toString();
hashSet.add(appName);
} catch (NameNotFoundException exception) {
// handle Exception
}
}
return hashSet;
}