Class PowerConfig



  • public class PowerConfig
    extends java.lang.Object
    This class is to allow us to know more about the device's current power configuration.
    • Field Detail

      • FIFTEEN_PERCENT_BATTERY_CHARGE

        public static final float FIFTEEN_PERCENT_BATTERY_CHARGE
        See Also:
        Constant Field Values
      • THIRTY_PERCENT_BATTERY_CHARGE

        public static final float THIRTY_PERCENT_BATTERY_CHARGE
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static PowerConfig getInstance(Context context)
        Gets the instance of PowerConfig

        If the instance has not been initialised then the first call to this method will activate the initialising code.

        Parameters:
        context - A context used to determine current battery and power state
        Returns:
        The instance of PowerConfig
      • isBatteryOk

        public boolean isBatteryOk()
        Determines if the current state of the battery is OK.

        A battery can be in an OK state (as determined by the OS) in one of two ways:

        • It is currently charging with AC power (even if the power remaining is < 15%)
        • It is not currently charging with AC power but has more than 30% power remaining

        Note that the system may not deem that the battery is OK again at exactly the same power capacity that initially triggered the low battery status.

        Also note that the very first time this method is called that it may be using a value that has been determined by ourselves. This is because the Intent#ACTION_BATTERY_LOW and Intent#ACTION_BATTERY_OKAY intents may not have been delivered yet. In such cases we deem the battery OK in the same was as the OS as described in the first paragraph.

        Returns:
        true if the battery is OK, false otherwise.
      • isBatteryLow

        public boolean isBatteryLow()
        This is the opposite of PowerConfig.isBatteryOk()

        A battery will be low when it is not charging and has less than 15% power remaining.

        Returns:
        true if the battery is low, false otherwise.
      • isGlobalSyncEnabled

        public boolean isGlobalSyncEnabled()
        Determines if global synchronisation is enabled.

        It is recommended to handle repeating tasks only when this is enabled.

        This method requires the caller to hold the permission Manifest.permission#READ_SYNC_SETTINGS. If the permission is not held then it will always return true.

        Returns:
        true if global synchronisation is enabled, false otherwise
      • isGlobalSyncDisabled

        public boolean isGlobalSyncDisabled()
        Determines if global synchronisation is disabled.

        If this is disabled then it is good practice to refrain from running any scheduled tasks involving the network.

        Returns:
        true if global synchronisation is disabled, false otherwise