Interface BatteryService

All Known Implementing Classes:
AndroidBatteryService, DummyBatteryService, IOSBatteryService

public interface BatteryService
With the battery service, you can query the current battery level of the underlying device and whether the device is currently plugged in to an external power source or not.

Example

 BatteryService.create().ifPresent(service -> {
      float batteryLevel = service.getBatteryLevel();
      boolean pluggedIn = service.isPluggedIn();
  });

Android Configuration: none

iOS Configuration: none

Since:
3.0.0
  • Property Summary

    Properties
    Type
    Property
    Description
    javafx.beans.property.ReadOnlyFloatProperty
    Returns a property that will be frequently updated to reflect the current battery level.
    javafx.beans.property.ReadOnlyBooleanProperty
    Returns a property that will be updated to reflect whether the device is plugged in to an external power source or not.
  • Method Summary

    Modifier and Type
    Method
    Description
    javafx.beans.property.ReadOnlyFloatProperty
    Returns a property that will be frequently updated to reflect the current battery level.
    Returns an instance of BatteryService.
    float
    Returns the current battery level of the device as a float between 0 and 1 (inclusive), where 0 indicates the battery is completely empty, and 1 indicates that the battery is fully charged.
    boolean
    A boolean representing whether the device is currently receiving power from an external source (i.e.
    javafx.beans.property.ReadOnlyBooleanProperty
    Returns a property that will be updated to reflect whether the device is plugged in to an external power source or not.
  • Property Details

    • batteryLevel

      javafx.beans.property.ReadOnlyFloatProperty batteryLevelProperty
      Returns a property that will be frequently updated to reflect the current battery level.
      See Also:
    • pluggedIn

      javafx.beans.property.ReadOnlyBooleanProperty pluggedInProperty
      Returns a property that will be updated to reflect whether the device is plugged in to an external power source or not.
      See Also:
  • Method Details

    • create

      static Optional<BatteryService> create()
      Returns an instance of BatteryService.
      Returns:
      An instance of BatteryService.
    • getBatteryLevel

      float getBatteryLevel()
      Returns the current battery level of the device as a float between 0 and 1 (inclusive), where 0 indicates the battery is completely empty, and 1 indicates that the battery is fully charged.
      Returns:
      A float value between 0 and 1 to indicate battery charge levels.
    • batteryLevelProperty

      javafx.beans.property.ReadOnlyFloatProperty batteryLevelProperty()
      Returns a property that will be frequently updated to reflect the current battery level.
      See Also:
    • isPluggedIn

      boolean isPluggedIn()
      A boolean representing whether the device is currently receiving power from an external source (i.e. it is not running on battery power).
      Returns:
      Returns true to indicate power is coming from an external source, and false to indicate that the battery is powering the device.
    • pluggedInProperty

      javafx.beans.property.ReadOnlyBooleanProperty pluggedInProperty()
      Returns a property that will be updated to reflect whether the device is plugged in to an external power source or not.
      See Also: