How to get a list of installed android applications and pick one to run

后端 未结 19 1830
误落风尘
误落风尘 2020-11-21 06:26

I asked a similar question to this earlier this week but I\'m still not understanding how to get a list of all installed applications and then pick one to run.

I\'v

相关标签:
19条回答
  • 2020-11-21 07:06

    Another way to filter on system apps (works with the example of king9981):

    /**
     * Return whether the given PackageInfo represents a system package or not.
     * User-installed packages (Market or otherwise) should not be denoted as
     * system packages.
     * 
     * @param pkgInfo
     * @return
     */
    private boolean isSystemPackage(PackageInfo pkgInfo) {
        return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
    }
    
    0 讨论(0)
  • 2020-11-21 07:06

    context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA); Should return the list of all the installed apps but in android 11 it'll only return the list of system apps. To get the list of all the applications(system+user) we need to provide an additional permission to the application i.e

    <uses-permission android:name"android.permission.QUERY_ALL_PACKAGES">

    0 讨论(0)
  • 2020-11-21 07:07

    You can Find the List of installed apps in Android Device by using below code, "packageInfo" Contains Installed Application Information in Device. we can retrive Intent for the application installed from the packageinfo object and by using startactivity(intent), can start application. it is up to you how you organize the UI either Listview or Gridview. so on click event based on position, you can retrive intent object and start activity intent.

    final PackageManager pm = getPackageManager();
    
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    
    
    for (ApplicationInfo packageInfo : packages) 
    
    {
     if(pm.getLaunchIntentForPackage(packageInfo.packageName)!= null &&   
    
                       !pm.getLaunchIntentForPackage(packageInfo.packageName).equals(""))
    
    
    {
    
        System.out.println("Package Name :" + packageInfo.packageName);
    
        System.out.println("Launch Intent For Package :"   +  
                      pm.getLaunchIntentForPackage(packageInfo.packageName));
    
        System.out.println("Application Label :"   + pm.getApplicationLabel(packageInfo));
    
        System.out.println("Application Label :"   + 
                               pm.getApplicationIcon(packageInfo.packageName).toString());
    
        System.out.println("i : "+i);
    
        /*if(i==2)
    
        {
             startActivity(pm.getLaunchIntentForPackage(packageInfo.packageName));
    
         break;
    
        }*/
    
        i++;
    
    }
    }
    
    0 讨论(0)
  • 2020-11-21 07:08

    Getting list of installed non-system apps

    public static void installedApps()
    {
        List<PackageInfo> packList = getPackageManager().getInstalledPackages(0);
        for (int i=0; i < packList.size(); i++)
        {
            PackageInfo packInfo = packList.get(i);
            if (  (packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
            {
                String appName = packInfo.applicationInfo.loadLabel(getPackageManager()).toString();
                Log.e("App № " + Integer.toString(i), appName);
            }
        }
    }
    
    0 讨论(0)
  • 2020-11-21 07:10

    I have another solution:

    ArrayList<AppInfo> myAppsToUpdate;
    
        // How to get the system and the user apps.
        public ArrayList<AppInfo> getAppsToUpdate() {
    
            PackageManager pm = App.getContext().getPackageManager();
            List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);
            myAppsToUpdate = new ArrayList<AppInfo>();
            for (ApplicationInfo aInfo : installedApps) {
    
                if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    // System apps 
                } else {
                    // Users apps
                    AppInfo appInfo = new AppInfo();
                    appInfo.setAppName(aInfo.loadLabel(pm).toString());
                    appInfo.setPackageName(aInfo.packageName);
                    appInfo.setLaunchActivity(pm.getLaunchIntentForPackage(aInfo.packageName).toString());
                    try {
                        PackageInfo info = pm.getPackageInfo(aInfo.packageName, 0);
                        appInfo.setVersionName(info.versionName.toString());
                        appInfo.setVersionCode("" + info.versionCode);
                        myAppsToUpdate.add(appInfo);
                    } catch (NameNotFoundException e) {
                        Log.e("ERROR", "we could not get the user's apps");
                    }
    
                }
            }
            return myAppsToUpdate;
        }
    
    0 讨论(0)
  • 2020-11-21 07:11

    To get al installed apps you can use Package Manager..

        List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
    

    To run you can use package name

    Intent launchApp = getPackageManager().getLaunchIntentForPackage(“package name”)
    startActivity(launchApp);
    

    For more detail you can read this blog http://codebucket.co.in/android-get-list-of-all-installed-apps/

    0 讨论(0)
提交回复
热议问题