Reputation: 2221
I am developing custom Android launcher and I have an option to uninstall apps directly from program list. Now, I would like to remove uninstall option for apps that can't get uninstalled, i.e. system apps, apps signed with platform keys...
I found in ActivityInfo
class following flags
/**
* 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;
but apparently, I get Unresolved reference: PRIVATE_FLAG_SYSTEM_EXT
compilation error, even though these flags are public
and static
. I am not sure why is that.
Is there any other way so I can check for given package name does that app belong to to system apps or to apps signed with platform key?
Checking for ApplicationInfo.FLAG_SYSTEM
and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
flags doesn't work for me for some reason.
Upvotes: 1
Views: 869
Reputation: 2221
Actually, ApplicationInfo.FLAG_SYSTEM
and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
flags do work, but they were tested against the wrong flags. Here is the correct code:
val applicationInfo = packageManager.getApplicationInfo(packageName, 0)
val isSystem =
(applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) ||
(applicationInfo.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0)
Upvotes: 2