當前位置: 首頁>>代碼示例>>Java>>正文


Java PackageManager.COMPONENT_ENABLED_STATE_DEFAULT屬性代碼示例

本文整理匯總了Java中android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT屬性的典型用法代碼示例。如果您正苦於以下問題:Java PackageManager.COMPONENT_ENABLED_STATE_DEFAULT屬性的具體用法?Java PackageManager.COMPONENT_ENABLED_STATE_DEFAULT怎麽用?Java PackageManager.COMPONENT_ENABLED_STATE_DEFAULT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.content.pm.PackageManager的用法示例。


在下文中一共展示了PackageManager.COMPONENT_ENABLED_STATE_DEFAULT屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: disableComponent

private void disableComponent() {
        PackageManager packageManager = getPackageManager();
        ComponentName componentName = new ComponentName(this, MainActivity.class);
//        packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
//                PackageManager.DONT_KILL_APP);
        int res = packageManager.getComponentEnabledSetting(componentName);
        if (res == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
                || res == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            // 隱藏應用圖標
            packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        } else {
            // 顯示應用圖標
            packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
                    PackageManager.DONT_KILL_APP);
        }
    }
 
開發者ID:gojuukaze,項目名稱:ScreenOffTime,代碼行數:17,代碼來源:MainActivity.java

示例2: Rule

private Rule(PackageInfo info, boolean wifi_blocked, boolean other_blocked, boolean changed, Context context) {
    PackageManager pm = context.getPackageManager();
    this.info = info;
    this.name = info.applicationInfo.loadLabel(pm).toString();
    this.system = ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);

    int setting = pm.getApplicationEnabledSetting(info.packageName);
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
        this.disabled = !info.applicationInfo.enabled;
    else
        this.disabled = (setting != PackageManager.COMPONENT_ENABLED_STATE_ENABLED);

    this.wifi_blocked = wifi_blocked;
    this.other_blocked = other_blocked;
    this.changed = changed;
}
 
開發者ID:shivam141296,項目名稱:Android-Firewall,代碼行數:16,代碼來源:Rule.java

示例3: isFrozen

public boolean isFrozen(Context context) {
	if (mFrozen == null) {
		PackageManager pm = context.getPackageManager();
		boolean enabled = false;
		for (ApplicationInfo appInfo : mMapAppInfo.values())
			try {
				int setting = pm.getApplicationEnabledSetting(appInfo.packageName);
				enabled = (enabled || setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
				enabled = (enabled || setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
				if (enabled)
					break;
			} catch (IllegalArgumentException ignored) {
			}
		mFrozen = !enabled;
	}
	return mFrozen;
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:17,代碼來源:ApplicationInfoEx.java

示例4: isComponentEnabled

@SuppressWarnings("deprecation")
public static boolean isComponentEnabled(PackageManager manager, ComponentName component) {
    switch (manager.getComponentEnabledSetting(component)) {
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            return false;
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            return true;
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
        default:
            try {
                PackageInfo packageInfo = manager.getPackageInfo(
                        component.getPackageName(),
                        PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES
                                | PackageManager.GET_PROVIDERS | PackageManager.GET_DISABLED_COMPONENTS);
                List<ComponentInfo> components = new ArrayList<>();
                if (packageInfo.activities != null) {
                    Collections.addAll(components, packageInfo.activities);
                }
                if (packageInfo.services != null) {
                    Collections.addAll(components, packageInfo.services);
                }
                if (packageInfo.providers != null) {
                    Collections.addAll(components, packageInfo.providers);
                }
                for (ComponentInfo componentInfo : components) {
                    if (componentInfo.name.equals(component.getClassName())) {
                        return componentInfo.isEnabled();
                    }
                }
                return false;
            } catch (PackageManager.NameNotFoundException e) {
                // the package isn't installed on the device
                return false;
            }
    }
}
 
開發者ID:Doist,項目名稱:JobSchedulerCompat,代碼行數:36,代碼來源:DeviceTestUtils.java

示例5: isComponentEnabled

public static boolean isComponentEnabled(PackageManager pm, String pkg, String cls) {
    ComponentName componentName = new ComponentName(pkg, cls);
    int componentEnabledSetting = pm.getComponentEnabledSetting(componentName);

    switch (componentEnabledSetting) {
        case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
            return false;
        case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
            return true;
        case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
        default:
            // We need to get the application info to get the component's default state
            try {
                PackageInfo packageInfo = pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES
                        | PackageManager.GET_RECEIVERS
                        | PackageManager.GET_SERVICES
                        | PackageManager.GET_PROVIDERS
                        | PackageManager.GET_DISABLED_COMPONENTS);

                List<ComponentInfo> components = new ArrayList<>();
                if (packageInfo.activities != null) Collections.addAll(components, packageInfo.activities);
                if (packageInfo.services != null) Collections.addAll(components, packageInfo.services);
                if (packageInfo.providers != null) Collections.addAll(components, packageInfo.providers);

                for (ComponentInfo componentInfo : components) {
                    if (componentInfo.name.equals(cls)) {
                        return componentInfo.enabled; //This is the default value (set in AndroidManifest.xml)
                        //return componentInfo.isEnabled(); //Whole package dependant
                    }
                }

                // the component is not declared in the AndroidManifest
                return false;
            } catch (PackageManager.NameNotFoundException e) {
                // the package isn't installed on the device
                return false;
            }
    }
}
 
開發者ID:RikkaW,項目名稱:Bridge,代碼行數:39,代碼來源:PackageManagerUtils.java

示例6: isEnabled

public static boolean isEnabled(PackageInfo info, Context context) {
    int setting;
    try {
        PackageManager pm = context.getPackageManager();
        setting = pm.getApplicationEnabledSetting(info.packageName);
    } catch (IllegalArgumentException ex) {
        setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
        return info.applicationInfo.enabled;
    else
        return (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}
 
開發者ID:miankai,項目名稱:MKAPP,代碼行數:14,代碼來源:Util.java

示例7: wasComponentEnabled

/**
 * 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;
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:21,代碼來源:LeanplumManifestHelper.java

示例8: onHideAppIconClicked

@OnClick(R.id.btn_hide_app_icon)
public void onHideAppIconClicked() {
    PackageManager manager = getPackageManager();
    ComponentName componentName = new ComponentName(this, MainActivity.class);
    int status = manager.getComponentEnabledSetting(componentName);
    if (status == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT ||
            status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
        manager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    } else {
        manager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
    }

}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:13,代碼來源:SystemActivity.java

示例9: isComponentDefault

/**
 * get the component in our package default
 * @param context
 * @param componentClassName
 */
public static boolean isComponentDefault(Context context, String componentClassName){
	PackageManager pm = context.getPackageManager();
	ComponentName componentName = new ComponentName(context.getPackageName(), componentClassName);
	return pm.getComponentEnabledSetting(componentName) == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
}
 
開發者ID:paozhuanyinyu,項目名稱:FreshMember,代碼行數:10,代碼來源:PackageUtils.java

示例10: checkApplicationEnabledSetting

public static boolean checkApplicationEnabledSetting(Context context, String packageName) {
    int state = context.getPackageManager().getApplicationEnabledSetting(packageName);
    return state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT ||
            state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:5,代碼來源:AppUtils.java


注:本文中的android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。