检查应用程序是否属于系统应用程序或使用平台密钥签名的应用程序
Check if app belongs to system apps or to apps signed with platform key
我正在开发自定义 Android 启动器,我可以选择直接从程序列表中卸载 应用程序。现在,我想为无法卸载的应用程序删除 uninstall 选项,即系统应用程序、使用平台密钥签名的应用程序...
我在 ActivityInfo
class 中找到以下标志
/**
* 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
编译错误,即使这些标志是 public
和 static
。我不确定为什么会这样。
有没有其他方法可以检查给定的包名称,该应用程序属于系统应用程序还是使用平台密钥签名的应用程序?
出于某种原因,检查 ApplicationInfo.FLAG_SYSTEM
和 ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
标志对我不起作用。
实际上,ApplicationInfo.FLAG_SYSTEM
和 ApplicationInfo.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)
我正在开发自定义 Android 启动器,我可以选择直接从程序列表中卸载 应用程序。现在,我想为无法卸载的应用程序删除 uninstall 选项,即系统应用程序、使用平台密钥签名的应用程序...
我在 ActivityInfo
class 中找到以下标志
/**
* 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
编译错误,即使这些标志是 public
和 static
。我不确定为什么会这样。
有没有其他方法可以检查给定的包名称,该应用程序属于系统应用程序还是使用平台密钥签名的应用程序?
出于某种原因,检查 ApplicationInfo.FLAG_SYSTEM
和 ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
标志对我不起作用。
实际上,ApplicationInfo.FLAG_SYSTEM
和 ApplicationInfo.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)