How to find out if an application is disabled in Android ICS

In Android ICS, we have the ability to disable embedded applications. Can I find out if a specific application is disabled or enabled in the code?

+2
source share
3 answers
ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo("your_package",0); boolean appStatus = ai.enabled; 

if appStatus is false , then the application is disconnected :)

+8
source

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; /** * @param context Context * @param packageName The Package name of the concerned App * @return State of the Application. * */ public static int getAppState(@NonNull Context context, @NonNull String packageName) { final PackageManager packageManager = context.getPackageManager(); // Check if the App is installed or not first Intent intent = packageManager.getLaunchIntentForPackage(packageName); if (intent == null) { return NOT_INSTALLED; } List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if(list.isEmpty()){ // App is not installed return NOT_INSTALLED; } else{ // Check if the App is enabled/disabled int appEnabledSetting = packageManager.getApplicationEnabledSetting(packageName); if(appEnabledSetting == COMPONENT_ENABLED_STATE_DISABLED || appEnabledSetting == COMPONENT_ENABLED_STATE_DISABLED_USER){ return DISABLED; } else{ return ENABLED; } } } 
+1
source
0
source

Source: https://habr.com/ru/post/973904/


All Articles