开发者

Determine that android package is preinstalled by vendor

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 i开发者_运维知识库nteresting whether Android Market app checks this preinstalled app for updates automatically like it's performed for Google Maps.


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.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜