Skip to content

[BUG] FlutterBackground is not initialised after letting app run in background #56

@victor-semenovich-dev

Description

@victor-semenovich-dev

Describe the bug
After run the FlutterBackground.initialize() command on the first app start, the application shows the "Let app always run in background?" dialog. If press "Allow", the FlutterBackground.initialize() returns false. FlutterBackground.enableBackgroundExecution() doesn't work after that. The bug is not reproduced on the second app run. In this case the dialog is not shown, and the FlutterBackground.initialize() returns true.

To Reproduce
Run the app at the first time and execute the FlutterBackground.initialize().

Expected behavior
FlutterBackground.initialize() returns "true" on press "Allow". FlutterBackground.enableBackgroundExecution() also works and returns "true".

Screenshots
Screenshot_20220413_101843

Smartphone:

  • Device: Google Pixel 5a
  • OS: Android 12

Code

class _HomeRouteState extends State<HomeRoute> {
  @override
  void initState() {
    super.initState();
    const androidConfig = FlutterBackgroundAndroidConfig(
      notificationTitle: 'Интерком',
      notificationText: 'Приложение работает в фоновом режиме',
      notificationImportance: AndroidNotificationImportance.Default,
      notificationIcon: AndroidResource(
        name: 'ic_info_24dp',
        defType: 'drawable',
      ),
      enableWifiLock: true,
    );
    FlutterBackground.initialize(androidConfig: androidConfig)
        .then((value) => debugPrint('FlutterBackground: initialize - $value'));
  }
...
}

[+12805 ms] I/flutter ( 7726): FlutterBackground: initialize - false
flutter doctor -v
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.3 21E230 darwin-x64, locale en-BY)
    • Flutter version 2.10.4 at /Users/victorsemenovich/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (3 weeks ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/victorsemenovich/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] Connected device (2 available)
    • Pixel 5a (mobile) • 192.168.0.14:41945 • android-arm64  • Android 12 (API 31)
    • Chrome (web)      • chrome             • web-javascript • Google Chrome 100.0.4896.88

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions