我想创建一个显示所有已启动应用程序的应用程序

时间:2015-05-19 11:12:49

标签: android

申请时间和名称已开启



final PackageManager pm = getPackageManager();
	packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
	
	for(ApplicationInfo packageInfo : packages )
	{
		  String name=packageInfo.getClass().getName();
		  Toast.makeText(ListActivity.this, ""+ name, 0).show();
	}




1 个答案:

答案 0 :(得分:2)

尝试此操作以获取正在运行的应用列表。

ActivityManager activity_manager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);

使用getRunningTasks()中的ActivityManager方法。

final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++) 
{
    Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");         
}

在清单文件中添加此权限。

<uses-permission android:name="android.permission.GET_TASKS" ></uses-permission>