-
- 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
Services.get(BatteryService.class).ifPresent(service -> { float batteryLevel = service.getBatteryLevel(); boolean pluggedIn = service.isPluggedIn(); });
Android Configuration: none
iOS Configuration: none
- Since:
- 3.0.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description javafx.beans.property.ReadOnlyFloatProperty
batteryLevelProperty()
Returns a property that will be frequently updated to reflect the current battery level.static java.util.Optional<BatteryService>
create()
Returns an instance ofBatteryService
.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.boolean
isPluggedIn()
A boolean representing whether the device is currently receiving power from an external source (i.e.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.
-
-
-
Method Detail
-
create
static java.util.Optional<BatteryService> create()
Returns an instance ofBatteryService
.- 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.- Returns:
- A property containing the current battery level.
-
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.- Returns:
- A property containing the plugged-in status of the device.
-
-