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

后端 未结 19 1889
误落风尘
误落风尘 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: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 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++;
    
    }
    }
    

提交回复
热议问题