检查应用是属于系统应用还是属于使用平台密钥签名的应用



我正在开发自定义Android启动器,我有一个选项卸载应用程序直接从程序列表。现在,我想删除卸载无法卸载的应用程序选项,例如系统应用程序,使用平台密钥签名的应用程序…

我发现在ActivityInfo类以下标志

/**
* Value for {@link #privateFlags}: whether this app is signed with the
* platform key.
* @hide
*/
public static final int PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY = 1 << 20;
/**
* Value for {@link #privateFlags}: whether this app is pre-installed on the
* system_ext partition of the system image.
* @hide
*/
public static final int PRIVATE_FLAG_SYSTEM_EXT = 1 << 21;

,但显然,我得到Unresolved reference: PRIVATE_FLAG_SYSTEM_EXT编译错误,即使这些标志是publicstatic。我不确定这是为什么。

是否有其他的方法,所以我可以检查给定的包名,该应用程序属于系统应用程序或与平台密钥签署的应用程序?

检查ApplicationInfo.FLAG_SYSTEMApplicationInfo.FLAG_UPDATED_SYSTEM_APP标志不为我工作,因为某些原因。

实际上,ApplicationInfo.FLAG_SYSTEMApplicationInfo.FLAG_UPDATED_SYSTEM_APP标志可以工作但他们的测试对象是错误的。下面是正确的代码:

val applicationInfo = packageManager.getApplicationInfo(packageName, 0)
val isSystem =
(applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) ||
(applicationInfo.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0)

相关内容

最新更新