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

后端 未结 2 1868
眼角桃花
眼角桃花 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<ResolveInfo> 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));
    }
    
    0 讨论(0)
  • 2021-01-25 09:59

    // How to detect which is the current top activity.

    public boolean whatIsCurrentActivity()  
    {  
     ActivityManager am = (ActivityManager) mContext.getSystemService(mContext.ACTIVITY_SERVICE);  
     List ActivityManager.RunningTaskInfo taskInfo = am.getRunningTasks(1);  
                   if(taskInfo != null ){  
                            System.out.println("Top activity - Package name of the process is "+taskInfo.get(0).topActivity.getPackageName() );  
           }  
    
    0 讨论(0)
提交回复
热议问题