Skip to content

DeviceSettings Android only

export interface DeviceSettings {

API for directing users to Android device settings screens that can affect background geolocation performance.

Many Android manufacturers apply aggressive battery optimizations that can kill background services, including the geolocation SDK. This API surfaces the relevant settings screens so users can whitelist your app.

For a comprehensive list of affected devices and manufacturers, see dontkillmyapp.com.

const isIgnoring = await BackgroundGeolocation.deviceSettings.isIgnoringBatteryOptimizations();
if (!isIgnoring) {
  const req = await BackgroundGeolocation.deviceSettings.showIgnoreBatteryOptimizations();
  if (!req.seen) {
    const confirmed = await showMyConfirmDialog({
      title: 'Settings request',
      text: 'Please disable battery optimizations for this app'
    });
    if (confirmed) {
      await BackgroundGeolocation.deviceSettings.show(req);
    }
  }
}

Members

isIgnoringBatteryOptimizations

isIgnoringBatteryOptimizations(): Promise<boolean>;

Android only Returns true if the OS is ignoring battery optimizations for your app.

In most cases the SDK performs acceptably even when battery optimizations are active, but aggressive manufacturer-specific restrictions may interfere with background operation.

show

show(request:DeviceSettingsRequest): Promise<boolean>;

Android only Execute a previously prepared DeviceSettingsRequest to open the target settings screen.

Resolves true if the redirect was attempted.

const req = await BackgroundGeolocation.deviceSettings.showPowerManager();
if (!req.seen) {
  await BackgroundGeolocation.deviceSettings.show(req);
}

showIgnoreBatteryOptimizations

showIgnoreBatteryOptimizations(): Promise<DeviceSettingsRequest>;

Android only Prepare a request to show the Android Ignore Battery Optimizations settings screen.

Returns a DeviceSettingsRequest rather than immediately redirecting, so you can inspect DeviceSettingsRequest.seen and decide whether to prompt the user.

Warning

On some devices and OS versions this screen may not be available. Always wrap calls to DeviceSettings.show in a try/catch.

See also - isIgnoringBatteryOptimizations - show

showPowerManager

showPowerManager(): Promise<DeviceSettingsRequest>;

Android only Prepare a request to show a vendor-specific Power Manager settings screen (Huawei, Xiaomi, Vivo, Oppo, etc.).

Returns a DeviceSettingsRequest rather than immediately redirecting.

Warning

Not all manufacturers or OS versions implement this screen. Always wrap calls to DeviceSettings.show in a try/catch.

See also - show