flutter_background icon indicating copy to clipboard operation
flutter_background copied to clipboard

[BUG] Doesn't work in real devices

Open Baldur008 opened this issue 3 years ago • 6 comments

Describe the bug It works in emulator but not in a real device

To Reproduce

FlutterBackground.initialize(
        androidConfig: FlutterBackgroundAndroidConfig(
          notificationTitle: "Running in Background",
          notificationImportance: AndroidNotificationImportance.Max,
          notificationText: "Your Location is being updated in background",
        ),
      )
FlutterBackground.enableBackgroundExecution();

Expected behavior I am calling both initialize and enablebackgroundexecution at the same time. It works on emulator but not in a real device

Smartphone:

  • Emulator: Pixel 4 API 29

Logs:

No Exception/Error Found.

Baldur008 avatar May 11 '22 21:05 Baldur008

enableBackgroundExecution requires the initialization to be finished. In the emulator, the initialization is presumably fast enough to be finished by chance. You should probably use await:

await FlutterBackground.initialize();
await FlutterBackground.enableBackgroundExecution();

If you need to do it in a non-async function, you can also do the following:

FlutterBackground.initialize().then((success) => FlutterBackground.enableBackgroundExecution());

Sesu8642 avatar May 26 '22 20:05 Sesu8642

Same issue for me. Working fine with emulator. I see that the await are done, but the app code is not running I am using:

const androidConfig = FlutterBackgroundAndroidConfig(
    notificationTitle: "App name",
    notificationText: "App is storing your location even when running in background",
    notificationImportance: AndroidNotificationImportance.Max,
    notificationIcon: AndroidResource(name: 'background_icon', defType: 'drawable'),
  );
  await FlutterBackground.initialize(androidConfig: androidConfig);
  await FlutterBackground.enableBackgroundExecution();

omerhertz avatar Aug 02 '22 13:08 omerhertz

The problem was in my real device configuration! I allowed my app to use location all the time, and it started working in the background too!

omerhertz avatar Aug 04 '22 12:08 omerhertz

There's definitely an issue on real devices. You have to initialise the configuration twice in order for it to work.

JavesonYehudi avatar Aug 05 '22 13:08 JavesonYehudi

same happened to me, on emulator works but on real devices throws

java.lang.RuntimeException: Unable to start service de.julianassmann.flutter_background.IsolateHolderService@8ca558 with Intent { act=START cmp=com.imvaswms.invaswmsdm/de.julianassmann.flutter_background.IsolateHolderService }: java.lang.IllegalArgumentException

innerk avatar Sep 30 '22 16:09 innerk

Unable to start service Intent { act=START cmp=com.deskbtm.nitmgpt/de.julianassmann.flutter_background.IsolateHolderService } U=0: not found

nawbc avatar Feb 26 '23 09:02 nawbc