3

I wonder whether there is a way to know that my app is preinstalled by vendor (and not installed from Android Market). Application is also available in Android Market and can be updated from there.

One solution is to create a file in the local file system (we can build a special app version for vendor). But there is a case that application can be updated from the market before its first run, and file is not created.

So is there any other way? Probably, installation path?

Also it's interesting whether Android Market app checks this preinstalled app for updates automatically like it's performed for Google Maps.

Roman Mazur
  • 3,084
  • 1
  • 20
  • 24
  • I answered this in a separate question: [preinstall with token file][1] [1]: http://stackoverflow.com/a/20457631/3070254 – gemigis Dec 08 '13 at 19:12

2 Answers2

5

You have to get the ApplicationInfo of your package (with the PackageManager) and then check its flags.

import android.content.pm.ApplicationInfo;

if ((ApplicationInfo.FLAG_SYSTEM & myApplicationInfo.flags) != 0)
   // It is a pre embedded application on the device.
Gorio
  • 1,606
  • 2
  • 19
  • 32
devMatt
  • 241
  • 1
  • 2
3

For a more complete example, one could use this:

private String getAllPreInstalledApplications() {

        String allPreInstalledApplications = "";

        PackageManager pm = getPackageManager();
        List<ApplicationInfo> installedApplications = pm
                .getInstalledApplications(PackageManager.GET_META_DATA);

        for (ApplicationInfo applicationInfo : installedApplications) {
            if (isApplicationPreInstalled(applicationInfo)) {
                allPreInstalledApplications += applicationInfo.processName + "\n";
            }
        }

        return allPreInstalledApplications;
}
private static boolean isApplicationPreInstalled(ApplicationInfo applicationInfo) {
    if (applicationInfo != null) {
        int allTheFlagsInHex = Integer.valueOf(
                String.valueOf(applicationInfo.flags), 16);
        /*
         If flags is an uneven number, then it
         is a preinstalled application, because in that case
         ApplicationInfo.FLAG_SYSTEM ( == 0x00000001 )
         is added to flags
          */
        if ((allTheFlagsInHex % 2) != 0) {
            return true;
        }
    }
    return false;
}
JoachimR
  • 5,150
  • 7
  • 45
  • 50