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 . 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 check out the related API usage on the sidebar.
Example 1
Source File: IDownloadManagerImpl.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
@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
Source File: PackageManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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 File: DownloadUtil.java    From Yuan-WanAndroid with 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 File: DownloadUtil.java    From WanAndroid with 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 File: UpdaterUtils.java    From AndroidUpdater with 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
Source File: DownloadManagerResolver.java    From FaceSlim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 File: GcmAvailableHelper.java    From android-job with 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
Source File: DownloadManagerResolver.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}