获取应用运行次数
PackageManager manager = context.getPackageManager();Intent intent = new Intent(Intent.ACTION_MAIN);List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);List<ComponentName> names = new ArrayList<ComponentName>();List<Map<String, String>> list = new ArrayList<Map<String, String>>();for (ResolveInfo info : infos) {ComponentName cn = new ComponentName(info.activityInfo.packageName,info.activityInfo.name);names.add(cn);}IUsageStats mUsageStatsService = IUsageStats.Stub.asInterface(ServiceManager.getService("usagestats"));for (ComponentName name : names) {PkgUsageStats aStats = null;ApplicationInfo info = null;try {aStats = mUsageStatsService.getPkgUsageStats(name);info = manager.getApplicationInfo(name.getPackageName(),PackageManager.GET_META_DATA);} catch (Exception e) {e.printStackTrace();}if (aStats != null && info != null) {String appName = info.loadLabel(manager).toString();int count = aStats.launchCount;if (count == 0) {continue;}Map<String, String> map = new HashMap<String, String>();map.put("appName", appName);map.put("count", count + "");list.add(map);}}