我该如何检查,如果一个应用程序在Android的非系统应用程序吗?应用程序、我该、系统、Android

2023-09-12 07:16:43 作者:离殇﹊落寂

我得到的名单 ApplicationInfo 对象与packageManager.getInstalledApplications(0)并试图通过他们是否是系统应用程序进行分类。

I am getting a list of ApplicationInfo Objects with packageManager.getInstalledApplications(0) and attempting to categorize them by whether or not they are a system application.

有一段时间,我一直使用描述的技术here,但是看到了,在我的应用程序后,某些应用程序没有在非系统的应用程序列表(比如的Facebook 的,它可以当要求系统在SD卡上自行安装)。之后下一个读取实际文档ApplicationInfo.FLAG_SYSTEM,和理解,它实际上并没有过滤系统的应用程序,我现在正在寻找一个新的方法。

For a while I have been using the technique described here, however after seeing that in my application, some of the apps were not in the non-system apps list (such as Facebook, which when available asks the system to install itself on the SD card). After next reading the actual documentation for ApplicationInfo.FLAG_SYSTEM, and understanding that it doesn't actually filter system apps, I am now looking for a new approach.

我的猜测是,有系统的UID和非系统的应用程序,我可以收集,使这个区别有很大的差距,但作为我却没有找到答案。我也看了成其他标志,如 ApplicationInfo.FLAG_EXTERNAL_STORAG​​E ,但是我支持的API 1.5。

My guess is that there is a large gap between UIDs of System and non-system apps that I can gather to make this distinction, but as of yet I have not found an answer. I also looked into other flags, such as ApplicationInfo.FLAG_EXTERNAL_STORAGE, however I am supporting API 1.5.

有没有人有一个真正的解决这个(不涉及 FLAG_SYSTEM )?

Does anyone have a real solution to this (not involving FLAG_SYSTEM)?

推荐答案

嗯,这是我认为一个草率的解决方案(如果的 /数据/应用程序的是不是所有设备上的应用程序目录? ),但仔细搜索后,这是我想出了:

Well, it's a sloppy solution in my opinion (what if /data/app isn't the apps directory on all devices?), but after a thorough search, this is what I have come up with:

for (ApplicationInfo ai : appInfo) {
    if (ai.sourceDir.startsWith("/data/app/")) {
        //Non-system app
    }
    else {
        //System app
    }
}