The accepted answer may also lead to an exception , i.e. NameNotFoundException , and therefore, you may need to create a thread that silently catches the exception and resolves the allowed state (in fact, this will be the third state, i.e. not installed).
So, it would be better to find the included as well as installed state as follows:
public static final int ENABLED = 0x00; public static final int DISABLED = 0x01; public static final int NOT_INSTALLED = 0x03; public static int getAppState(@NonNull Context context, @NonNull String packageName) { final PackageManager packageManager = context.getPackageManager();
source share