0

How to get exactly "Unknown Sources" application list on Android? what is flag to used? If it is not this method,what are others method? and How to programmically?

    PackageManager pm = this.getPackageManager();
    final List<PackageInfo> appinstalled = pm
            .getInstalledPackages(what is flag??); //

Sorry for my bad English. Thank you.

Indyway
  • 1
  • 1

2 Answers2

0

I know this is an old post but I think the following answer might help you: https://stackoverflow.com/a/42248268/2212770

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;
}
Community
  • 1
  • 1
Wirling
  • 4,810
  • 3
  • 48
  • 78
0

Someone else may have a better solution, but here's the best I could come up with...

Iterate through all installed packages, comparing each one against a known "good" package that has a good signature, with checkSignatures(int, int) or checkSignatures(String, String). If the return value of checkSignatures is SIGNATURE_UNKNOWN_PACKAGE, then you've got a package from an unknown source.

Otherwise, it doesn't look like any of the flags to getInstalledPackages are intended to filter for unknown sources.

Thane Anthem
  • 4,093
  • 4
  • 26
  • 24