2

My ultimate goal is to give the user the ability to open another app (such as Google chrome, etc) from my app. My attempt is to create an array with all the installed apps and their package names and use an Intent to open the third party app using the package name.

I am not sure how to go through the phone and find the package names. Can someone direct me in the right direction?

user2779837
  • 301
  • 3
  • 15

2 Answers2

1

Use PackageManager:

PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) 
{
    Log.d(TAG, "Installed package :" + packageInfo.packageName);
    Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
}
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
1

If you want to get and show only the downloaded application (not system application) then just use this code it will solve your problem.

    List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
    for (int i = 0; i < packs.size(); i++) 
    {
        PackageInfo packageInfo = packs.get(i);
        ApplicationInfo applicationInfo = packageInfo.applicationInfo;
        // Skips the system application (packages)
        if ( applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
        {
            continue;
        }

        String name = packageInfo.packageName;
        String versionName = packageInfo.versionName;
        String versionCode = packageInfo.versionCode;
       }
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81