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

The following examples show how to use android.content.pm.PackageManager#COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED . 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
@Override
public synchronized boolean isDownloadManagerEnabled(){
    if(context==null){
        return false;
    }

    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) {
        //download manager is disabled
        return false;
    }
    return true;
}
 
Example 2
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 3
Source Project: Yuan-WanAndroid   File: DownloadUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 是否可以使用DownloadManager,如果不能则使用系统浏览器
 */
public static boolean canDownloadState(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 4
Source Project: WanAndroid   File: DownloadUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 是否可以使用DownloadManager,如果不能则使用系统浏览器
 */
public static boolean canDownloadState(Context ctx) {
    try {
        int state = ctx.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 5
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 6
/**
 * 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 7
Source Project: android-job   File: GcmAvailableHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static void setServiceEnabled(Context context, boolean enabled) {
    try {
        PackageManager packageManager = context.getPackageManager();

        // use a string, the class object probably cannot be instantiated
        ComponentName component = new ComponentName(context, getPlatformGcmServiceClassName());

        int componentEnabled = packageManager.getComponentEnabledSetting(component);
        switch (componentEnabled) {
            case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
                if (!enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                    CAT.i("GCM service disabled");
                }
                break;

            case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT: // default is disable
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED:
                if (enabled) {
                    packageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                    CAT.i("GCM service enabled");
                }
                break;
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED:
            case PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER:
                // do nothing
                break;
        }

    } catch (Throwable t) {
        // just in case, don't let the app crash with each restart
        if (BuildConfig.DEBUG) {
            CAT.e(t.getMessage());
        }
    }
}
 
Example 8
/**
 * 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);
    }
}