Java Code Examples for android.content.pm.PackageManager#COMPONENT_ENABLED_STATE_DISABLED

The following examples show how to use android.content.pm.PackageManager#COMPONENT_ENABLED_STATE_DISABLED . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: WiFiKeyView   File: DebugPreferences.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
	if (key.equals("hide_launcher_icon")) {
		int newState = (sharedPreferences.getBoolean(key, false)) ? 
				PackageManager.COMPONENT_ENABLED_STATE_DISABLED : 
					PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
		
		PackageManager packageManager = 
				getActivity().getPackageManager();
		ComponentName componentName = 
				new ComponentName(getActivity(), "com.whd.wifikeyview.preferences.SettingsActivity-Alias");
		
		int oldState = packageManager.getComponentEnabledSetting(componentName);
		
		if (newState != oldState) {
			packageManager.setComponentEnabledSetting(componentName, newState, PackageManager.DONT_KILL_APP);
		}
	}
}
 
Example 2
/**
 * Detect the current "Autostart if card is detected" state and set
 * the checkbox accordingly.
 */
private void detectAutostartIfCardDetectedState() {
    int enabledSetting = mPackageManager.getComponentEnabledSetting(
            mComponentName);
    switch (enabledSetting) {
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            mPrefAutostartIfCardDetected.setChecked(true);
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            mPrefAutostartIfCardDetected.setChecked(false);
            break;
        default:
            break;
    }
}
 
Example 3
Source Project: droidconat-2016   File: AppDumperPlugin.java    License: Apache License 2.0 6 votes vote down vote up
private void displayBootReceiverState(PrintStream writer) {
    ComponentName componentName = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();

    writer.print("Boot receiver state: ");
    int state = pm.getComponentEnabledSetting(componentName);
    switch (state) {
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            writer.println("default");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            writer.println("enabled");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            writer.println("disabled");
            break;
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
            writer.println("disabled by user");
            break;
        default:
            writer.println(state);
            break;
    }
}
 
Example 4
private void applyComponentEnablingState(boolean active) {
    int enableState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if(active && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.INTEGRATE_TEL_PRIVILEGED) ) {
           // Check whether we should register for stock tel: intents
           // Useful for devices without gsm
           enableState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    }
       PackageManager pm = getPackageManager();
       
       ComponentName cmp = new ComponentName(this, "com.csipsimple.ui.PrivilegedOutgoingCallBroadcaster");
       try {
           if (pm.getComponentEnabledSetting(cmp) != enableState) {
               pm.setComponentEnabledSetting(cmp, enableState, PackageManager.DONT_KILL_APP);
           }
       } catch (IllegalArgumentException e) {
           Log.d(THIS_FILE,
                   "Current manifest has no PrivilegedOutgoingCallBroadcaster -- you can ignore this if voluntary", e);
       }
}
 
Example 5
/**
 * Resolve whether the DownloadManager is enable in current devices.
 *
 * @param context
 * @return true if DownloadManager is enable,false otherwise.
 */
private static boolean resolveEnable(Context context) {
    int state = context.getPackageManager()
            .getApplicationEnabledSetting(DOWNLOAD_MANAGER_PACKAGE_NAME);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED);
    } else {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER);
    }
}
 
Example 6
public static void setEnabled (Context context, boolean enable) {
	if (context == null)
		return;
	PackageManager pm = context.getPackageManager();
	if (pm == null)
		return;
	ComponentName component = new ComponentName (context, WifiBroadcastReceiver.class);
	int status = pm.getComponentEnabledSetting(component);
	int statusNew = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
	if (status != statusNew)
		pm.setComponentEnabledSetting(component,  statusNew, PackageManager.DONT_KILL_APP);
}
 
Example 7
/**
 * Resolve whether the DownloadManager is enable in current devices.
 *
 * @param context Context of application
 * @return true if DownloadManager is enable, false otherwise.
 */
private static boolean resolveEnable(Context context) {
    int state = context.getPackageManager()
            .getApplicationEnabledSetting(DOWNLOAD_MANAGER_PACKAGE_NAME);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED);
    } else {
        return !(state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED ||
                state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER);
    }
}
 
Example 8
Source Project: AndroidUpdater   File: UpdaterUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 系统的下载组件是否可用
 *
 * @return boolean
 */
public static boolean checkDownloadState(Context context) {
    try {
        int state = context.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");
        if (state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
                || state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example 9
private static String enabledSettingToString(int state) {
    switch (state) {
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
            return "default";
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            return "enabled";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            return "disabled";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
            return "disabled-user";
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
            return "disabled-until-used";
    }
    return "unknown";
}
 
Example 10
private void setHandleHttpScheme(boolean handleHttpScheme) {
    if(handleHttpScheme == isHandlingHttpScheme()) return;

    int flag = (handleHttpScheme ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED);

    getPackageManager().setComponentEnabledSetting(
            getHttpSchemeHandlingComponent(), flag, PackageManager.DONT_KILL_APP);
}
 
Example 11
/**
 * Checks if component for provided class enabled before.
 *
 * @param context Current Context.
 * @param packageManager Current PackageManager.
 * @param clazz Class for check.
 * @return True if component was enabled before.
 */
public static boolean wasComponentEnabled(Context context, PackageManager packageManager,
    Class clazz) {
  if (clazz == null || context == null || packageManager == null) {
    return false;
  }
  int componentStatus = packageManager.getComponentEnabledSetting(new ComponentName(context,
      clazz));
  if (PackageManager.COMPONENT_ENABLED_STATE_DEFAULT == componentStatus ||
      PackageManager.COMPONENT_ENABLED_STATE_DISABLED == componentStatus) {
    return false;
  }
  return true;
}
 
Example 12
/**
 * Enable/Disable Broadcast Receiver
 *
 * @param context the context
 * @param brClass the br class
 * @param enabled the enabled
 */
public static void setStateOfReceiver(Context context, Class<?> brClass, boolean enabled) {
    ComponentName receiverName = new ComponentName(context, brClass.getName());
    PackageManager pm = context.getPackageManager();

    int newstate;
    if (enabled) {
        newstate = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    } else {
        newstate = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }

    pm.setComponentEnabledSetting(receiverName, newstate, PackageManager.DONT_KILL_APP);
}
 
Example 13
Source Project: Android-Next   File: PackageUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setComponentState(Context context, Class<?> clazz, boolean enable) {
    ComponentName componentName = new ComponentName(context, clazz);
    PackageManager pm = context.getPackageManager();
    final int oldState = pm.getComponentEnabledSetting(componentName);
    final int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (newState != oldState) {
        final int flags = PackageManager.DONT_KILL_APP;
        pm.setComponentEnabledSetting(componentName, newState, flags);
    }
}
 
Example 14
public void hideLauncherIcon(boolean isHide) {
    PackageManager packageManager = this.getPackageManager();
    int hide = isHide ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
            : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    packageManager.setComponentEnabledSetting(getAliasComponentName(),
            hide, PackageManager.DONT_KILL_APP);
}
 
Example 15
Source Project: HideMockLocation   File: SettingsFragment.java    License: MIT License 5 votes vote down vote up
private void changeIconView(boolean showIcon) {
    PackageManager packageManager = getActivity().getPackageManager();
    int state = showIcon ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    String alias_package = Common.PACKAGE_NAME + ".MainAlias";
    ComponentName alias = new ComponentName(getActivity(), alias_package);
    packageManager.setComponentEnabledSetting(alias, state,
            PackageManager.DONT_KILL_APP);
}
 
Example 16
public static void hideOrShowLauncher(Context context, boolean isHide) {
    PackageManager p = context.getPackageManager();
    ComponentName componentName = new ComponentName(context, SettingActivity.class);
    if (isHide) {
        if (p.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
            p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            Log.d("PropUtil", "Hide the icon.");
        }
    } else {
        if (p.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            Log.d("PropUtil", "Show the icon.");
        }
    }
}
 
Example 17
public boolean isHideLauncherIcon() {
    return mPackageManager.getComponentEnabledSetting(LAUNCH_COMPONENT_NAME)
            == PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}
 
Example 18
public void hideLauncherIcon(boolean isHide) {
    PackageManager packageManager = this.getPackageManager();
    int hide = isHide ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    packageManager.setComponentEnabledSetting(getAliasComponentName(), hide, PackageManager.DONT_KILL_APP);
}
 
Example 19
public void hideLauncherIcon(boolean isHide) {
    PackageManager packageManager = this.getPackageManager();
    int hide = isHide ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    packageManager.setComponentEnabledSetting(getAliasComponentName(), hide, PackageManager.DONT_KILL_APP);
}
 
Example 20
private void toggleLauncherIcon(boolean newValue) {
    PackageManager packageManager = this.getPackageManager();
    int state = newValue ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    packageManager.setComponentEnabledSetting(getIconComponentName(), state, PackageManager.DONT_KILL_APP);
}