Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get list of non Play Store apps

As a safety measure I would like to get the list of apps that aren't installed from the Play Store. Is there a way to do this?

The packageManager contains a method getInstalledApplications but I don't know which flags to add to get the list. Any help would be appreciated.

Edit: Here is an code example of v4_adi's answer.

public static List<String> getAppsFromUnknownSources(Context context)
{
  List<String> apps = new ArrayList<>();
  PackageManager packageManager = context.getPackageManager();
  List<PackageInfo> packList = packageManager.getInstalledPackages(0);
  for (int i = 0; i < packList.size(); i++)
  {
     PackageInfo packInfo = packList.get(i);
     if (packageManager.getInstallerPackageName(packInfo.packageName) == null)
     {
        apps.add(packInfo.packageName);
     }
  }

  return apps;
}

This is a good start, however this also returns a lot off pre-installed Android and Samsung apps. Is there anyway to remove them from the list? I only want user installed apps from unknown sources.

like image 737
Wirling Avatar asked Oct 21 '25 01:10

Wirling


2 Answers

The following link has answer to your question The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.

How to know an application is installed from google play or side-load?

like image 75
v4_adi Avatar answered Oct 22 '25 14:10

v4_adi


Originally I thought it would be enough to retrieve the apps that weren't installed via the Google Play Store. Later I found that I also needed to filter out the pre-installed system applications. I found the last part of the puzzle in another post: Get list of Non System Applications

public static List<String> getAppsFromUnknownSources(Context context)
{
  List<String> apps = new ArrayList<>();
  PackageManager packageManager = context.getPackageManager();
  List<PackageInfo> packList = packageManager.getInstalledPackages(0);
  for (int i = 0; i < packList.size(); i++)
  {
     PackageInfo packInfo = packList.get(i);
     boolean hasEmptyInstallerPackageName = packageManager
           .getInstallerPackageName(packageInfo.packageName) == null;
     boolean isUserInstalledApp = (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0;

     if (hasEmptyInstallerPackageName && isUserInstalledApp)
     {
        apps.add(packInfo.packageName);
     }
  }

  return apps;
}
like image 38
Wirling Avatar answered Oct 22 '25 16:10

Wirling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!