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

后端 未结 19 1884
误落风尘
误落风尘 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:20

    Here's a cleaner way using the PackageManager

    final PackageManager pm = getPackageManager();
    //get a list of installed apps.
    List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    
    for (ApplicationInfo packageInfo : packages) {
        Log.d(TAG, "Installed package :" + packageInfo.packageName);
        Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
        Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
    }
    // the getLaunchIntentForPackage returns an intent that you can use with startActivity() 
    

    More info here http://qtcstation.com/2011/02/how-to-launch-another-app-from-your-app/

提交回复
热议问题