auto_start_flutter 0.3.0 copy "auto_start_flutter: ^0.3.0" to clipboard
auto_start_flutter: ^0.3.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.

pub package

Getting Started #

Add the package to your pubspec.yaml:

dependencies:
  auto_start_flutter: ^0.3.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.

  1. Check Availability: Check if the current device has a known "Auto-Start" setting.

    bool isAvailable = await isAutoStartAvailable ?? false;
    
  2. 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();
      }
    }
    
  3. 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();
    
  4. Custom Settings (Advanced): If you know the specific package and activity name for a setting page on a specific device, you can attempt to open it directly.

    // Example: Try opening a specific hidden setting
    await openCustomSetting(
      packageName: 'com.android.settings',
      activityName: 'com.android.settings.Settings\$PowerUsageSummaryActivity',
    );
    

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.

  1. Check Status: Check if your app is already ignoring battery optimizations.

    bool isExempt = await isBatteryOptimizationDisabled ?? false;
    print("Battery Optimization Disabled: $isExempt");
    
  2. 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.

71
likes
0
points
1.69k
downloads

Publisher

verified publishertechflow.ir

Weekly Downloads

The plugin redirects the user to auto-start permission screen to allow auto-start and fix background problems in some phones.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on auto_start_flutter

Packages that implement auto_start_flutter