DeviceSettings class
Device Settings API.
Provides an API to show Android & vendor-specific Battery / Power Management settings screens that can affect performance of the Background Geolocation SDK on various devices.
The site Don't Kill My App provides a comprehensive list of poor Android vendors which throttle background-services that this plugin relies upon.
This DeviceSettings
API is an attempt to provide resources to direct the user to the appropriate vendor-specific settings screen to resolve issues with background operation.
Example
// Is Android device ignoring battery optimizations?
bool isIgnoring = await DeviceSettings.isIgnoringBatteryOptimizations;
if (!isIgnoring) {
DeviceSettings.showIgnoreBatteryOptimizations().then((DeviceSettingsRequest request) {
print("- Screen seen? ${request.seen} ${request.lastSeenAt}");
print("- Device: ${request.manufacturer} ${request.model} ${request.version}");
// If we've already shown this screen to the user, we don't want to annoy them.
if (request.seen) {
return;
}
// It's your responsibility to instruct the user what exactly
// to do here, perhaps with a Confirm Dialog:
showMyConfimDialog(
title: "Settings request",
text: "Please disable battery optimizations for your device"
).then((bool confirmed) {
if (confirmed) {
// User clicked [Confirm] button. Execute the redirect to settings screen:
DeviceSettings.show(request);
}
});
}).catchError((dynamic error) {
// Depending on Manufacturer/Model/OS Version, a Device may not implement
// a particular Settings screen.
print(error);
});
}
// Is iOS/Android device in power-saving mode?
bool isPowerSaving = await DeviceSettings.isPowerSaveMode;
// Show Android vendor-specific "Power Manager" device settings screen (eg: Huawei)
DeviceSettings.showPowerManager();
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
isIgnoringBatteryOptimizations
→ Future<
bool> -
Returns
true
if device is ignoring battery optimizations for your app.no setter -
isPowerSaveMode
→ Future<
bool> -
Fetches the state of the operating-system's "Power Saving" mode.
no setter
Static Methods
-
show(
DeviceSettingsRequest request) → Future< bool> - This method is designed to be executed from a showPowerManager or showIgnoreBatteryOptimizations callback.
-
showIgnoreBatteryOptimizations(
) → Future< DeviceSettingsRequest> - Shows the Android Ignore Battery Optimizations settings screen.
-
showPowerManager(
) → Future< DeviceSettingsRequest> - Shows a vendor-specific "Power Management" screen.
Constants
- IGNORE_BATTERY_OPTIMIZATIONS → const String
- POWER_MANAGER → const String