auto_start_flutter 0.2.0
auto_start_flutter: ^0.2.0 copied to clipboard
The plugin redirects the user to auto-start permission screen to allow auto-start and fix background problems in some phones.
auto_start_flutter #
A Flutter plugin to help manage background execution permissions on Android devices. It supports requesting "Auto-Start" permissions on specific OEM devices (Xiaomi, Oppo, Vivo, etc.) and managing battery optimization settings to ensure your app can run reliably in the background.
Features #
- Auto-Start Permission: Open the manufacturer-specific "Auto-Start" or "App Launch" settings.
- Battery Optimization: Check if the app is exempt from battery optimizations and open settings to request exemption.
- Device Support: targeted support for Xiaomi, Redmi, Poco, Oppo, Vivo, Huawei, Honor, Samsung, ASUS, OnePlus, Nokia, LeTV, Meizu, HTC, Infinix, and more.
- Robustness: The plugin attempts multiple known intents for each manufacturer to ensure the settings page opens correctly.
Getting Started #
Add the package to your pubspec.yaml:
dependencies:
auto_start_flutter: ^0.2.0
Import the package:
import 'package:auto_start_flutter/auto_start_flutter.dart';
Usage #
Auto-Start Permission #
Many Android manufacturers (Xiaomi, Oppo, Vivo, etc.) have a custom "Auto-Start" permission that prevents apps from starting in the background by default.
-
Check Availability: Check if the current device has a known "Auto-Start" setting.
bool isAvailable = await isAutoStartAvailable ?? false; -
Request Permission: If available, navigate the user to the settings page.
if (isAvailable) { bool success = await getAutoStartPermission(); if (success) { // Successfully opened Auto-Start settings } else { // Failed to open Auto-Start settings, usually because the specific intent wasn't found. // You might want to fallback to App Info. await openAppInfo(); } } -
Fallback & Customization: You can also check the manufacturer to show specific instructions or use the generic App Info page as a fallback.
String? manufacturer = await getDeviceManufacturer(); if (manufacturer == "xiaomi") { // Show specific instructions for Xiaomi users } // Open standard App Info page await openAppInfo();
Battery Optimization #
Android's Doze mode and App Standby can restrict background processing. Disabling battery optimizations for your app can help ensure background services (like Alarms or WorkManager) run on time.
-
Check Status: Check if your app is already ignoring battery optimizations.
bool isExempt = await isBatteryOptimizationDisabled ?? false; print("Battery Optimization Disabled: $isExempt"); -
Open Settings: If not exempt, open the "Ignore Battery Optimization" settings to let the user allow your app.
if (!isExempt) { await disableBatteryOptimization(); }
Platform Support #
| Platform | Supported | Notes |
|---|---|---|
| Android | ✅ | Supports custom OEM intents and standard battery optimization settings. |
| iOS | ❌ | Not applicable. |
contributing #
If you find any issues or would like to add support for more devices, please file an issue or pull request on GitHub.