Back to top

Data saver

Data Saver is a feature that allows users to restrict background data in an app, which may prevent it from working properly. The Knox SDK uses the AllowDataSaving API to control a users access to the Data Saver feature. This can be used globally or on a per app basis. Users can also restrict data access while roaming using Knox SDK.

allowDataSaving()

You use allowdataSaving() to control the Data Saver feature on your device.

  • allowDataSaving == true — Allows Data Saver to be turned on or off by the user.
  • allowDataSaving() == false — Turns Data Saver off and prevents users from turning it back on. In addition, this also turns on background data usage for all apps.

This API is more restrictive than setBackgroundData(). If set to false it will take precedence over it.

EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
        RestrictionPolicy restrictionPolicy = edm.getRestrictionPolicy();
        try {
            // disallow Data Saving
            boolean result = restrictionPolicy.allowDataSaving(false);

            if (true == result) {
                // Data Saving is disabled and cannot be enabled by user.
            }
        } catch (SecurityException e) {
            Log.w(TAG, "SecurityException: " + e);
        }
        // enable Data Saver UI control
        try {
            boolean result = restrictionPolicy.allowDataSaving(true);
            if (true == result) {
                // Data Saver UI control is enabled and user can change it.
            }
        } catch (SecurityException e) {
            Log.w(TAG, "SecurityException: " + e);
        }

isDataSavingAllowed()

You use isdataSavingAllowed() to check whether the Data Saver feature is allowed or not allowed on the device.

EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
        RestrictionPolicy restrictionPolicy = edm.getRestrictionPolicy();
        boolean result = false;
        try {
            // Check Data Saver is allowed
            result = restrictionPolicy.isDataSavingAllowed();
        } catch (RemoteException e) {
            Log.e(TAG, "Remote exception : " + e);
        }

Is this page helpful?