showPowerManager static method

Future<DeviceSettingsRequest> showPowerManager()

Shows a vendor-specific "Power Management" screen.

For example, a Huawei device will show the Battery->Launch screen:

The site Don't Kill My App provides a comprehensive list of poor Android vendors which throttle background-services that this plugin relies upon.

showPowerManager does not immediately redirect to the desired Device settings screen. Instead, it first returns a DeviceSettingsRequest, containing meta-data about the device (manufacturer, model, version), in addition to a flags seen and lastSeenAt, letting you know if and when you've already shown this screen to the user.

Unfortunately, there's no possible way to determine if the user actually performs the desired action to "white list" your app on the shown settings-screen. For this reason, you'll have to evaluate the provided properties DeviceSettingsRequest.seen] & DeviceSettingsRequest.lastSeenAt and determine for yourself whether to DeviceSettings.show this screen.

In your success-callback, it's completely up to you to instruct the user what exactly to do on that screen, based upon the provided DeviceSettingsRequest properties manufacturer, model and version.

Note: Based upon the manufacturer / model / OS version, a Device may not have a particular Settings screen implemented (eg: Google Pixel). In this case, the Promise will fire an exception.

Example

DeviceSettings.showPowerManager().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:
  showMyConfirmDialog(
    title: "Device Power Management",
    text: "Please white-list the app in your Device's Power Management settings by clicking this then selecting that."
  ).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);
});

Vendor Settings Screens

The following Android Settings screen will be shown depending on Vendor / OS version:

Vendor Settings Activity Name
LeEco AutobootManageActivity
Huawei StartupAppControlActivity,StartupAppControlActivity (depends on OS version)
Color OS StartupAppListActivity
OPPO StartupAppListActivity
Vivo BgStartUpManagerActivity,AddWhiteListActivity,BgStartUpManager (depends on OS version)
Samsung BatteryActivity
HTC LandingPageActivity
Asus AutobootManageActivity
LeEco mobilemanager.MainActivity

Implementation

static Future<DeviceSettingsRequest> showPowerManager() async {
  List<dynamic> args = [POWER_MANAGER];
  Map request =
      (await _methodChannel.invokeMapMethod('requestSettings', args))!;
  return new DeviceSettingsRequest(
      action: request['action'],
      manufacturer: request['manufacturer'],
      model: request['model'],
      version: request['version'],
      seen: request['seen'],
      lastSeenAt: request['lastSeenAt']);
}