How can get how many apps installed in my device and there names or last accessed information?

后端 未结 2 1875
眼角桃花
眼角桃花 2021-01-25 09:35

I need to show the last accessed app information in my app. How can i get this information?

2条回答
  •  爱一瞬间的悲伤
    2021-01-25 09:51

    You can use this code to get the list of applications:

    PackageManager pm = this.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    
    String activityName = rInfo.activityInfo.name;
    List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
    
    for (ResolveInfo rInfo : list) {
        pkg = rInfo.activityInfo.applicationInfo.packageName;
        if (pm.getLaunchIntentForPackage(pkg) == null) {
          continue;
        }
        String label = rInfo.activityInfo.applicationInfo.loadLabel(pm).toString();
        arrayList.add(new AppEntry(label, activityName, pkg, null));
    }
    

提交回复
热议问题