autostart_settings 0.1.2 copy "autostart_settings: ^0.1.2" to clipboard
autostart_settings: ^0.1.2 copied to clipboard

PlatformAndroid

Plugin to check if autostart settings is available for the device and opens the autostart settings

Opens device specific autostart settings. #

pub package

Many manufacturers disable apps from auto starting by default. This prevents scheduled local notifications or background tasks after the device got rebooted.

This plugin links the user to the settings page where the user can enable autostart permission for selected apps. It also can navigate the user to device specific battery safer permission, where the user can select apps that shouldn't be killed in the background.

Currently this plugin support a wide variety of manufacturers gathered over the years;

  • Asus
  • HTC
  • Huawei
  • IQOO
  • LeEco
  • Mediatek
  • Meizu
  • Nokia
  • OnePlus
  • Oppo
  • Samsung
  • Tecno
  • Vivo
  • Xiaomi / Redmi
Android
Support 14+

The example app running on Redmi 7A

Installation #

First, add autostart_settings as a dependency in your pubspec.yaml file.

Usage #

import 'package:autostart_settings/autostart_settings.dart';

final canOpen = await AutostartSettings.canOpen(autoStart: true, batterySafer: true);
if (canOpen) {
    final opened = await AutostartSettings.open(autoStart: true, batterySafer: true);
}

Example #

import 'package:flutter/material.dart';
import 'package:autostart_settings/autostart_settings.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _text = '';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Autostart example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: ElevatedButton(
                    onPressed: () async {
                      final canOpen = await AutostartSettings.canOpen(
                          autoStart: true, batterySafer: true);
                      setState(() {
                        if (canOpen) {
                          _text = 'device can open autostart Settings';
                        } else {
                          _text = 'device doesn\'t have autostart settings activity';
                        }
                      });
                    },
                    child: const Text('openSettings')),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: ElevatedButton(
                    onPressed: () async {
                      final opened = await AutostartSettings.open(
                          autoStart: true, batterySafer: true);
                      setState(() {
                        _text = 'Settings opened: $opened';
                      });
                    },
                    child: const Text('openSettings')),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(_text),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Recommendation #

I would recommend for better reliability to also request ignoreBatteryOptimizations permission from the permission_handler plugin:

import 'package:permission_handler/permission_handler.dart';

await Permission.ignoreBatteryOptimizations.request();

Contribute #

If you own a device where the autostart settings page is not yet added, would be grateful if yo contribute, these adb-commands might help identify the correct activity:

  • list all activityName: adb shell dumpsys package | grep Activity
  • finding current active/resumed activity: adb shell dumpsys activity activities | grep mResumedActivity
0
likes
130
pub points
49%
popularity
screenshot

Publisher

verified publisherc-wolf.dev

Plugin to check if autostart settings is available for the device and opens the autostart settings

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on autostart_settings