Skip to content

NfcManager.instance.startSession doesn't work in Background #81

@ghost

Description

Describe the bug
I would like to make an app that periodically reads NFC tags in the background.
When it goes into background execution the NfcManager part is not executed.

To Reproduce
This is the part of code that we call when a button is pressed. It works when the app is on the screen, when we hide the screen, the part of NfcManager doesn't run. No error appears.

if (hasPermissions) {
final backgroundExecution =
await FlutterBackground.enableBackgroundExecution();
ValueNotifier resultBro = ValueNotifier(null);
if (backgroundExecution) {
print("SONO IN back, BRO");
timer = Timer.periodic(Duration(seconds: 5), (Timer t) async {
Duration tagtimer = Duration(seconds: 3);
resultBro.value = null;

    Timer(tagtimer, () async {
      if (resultBro.value == null) {
        await NfcManager.instance.stopSession();
      }
    });
    NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
      resultBro.value = tag.data;
      print("sto in on discover bro");
      print(resultBro.value);
      await NfcManager.instance
          .stopSession()
          .whenComplete(() => print("so completo bro"));
    });
    print("sto fuori bro");
    print(resultBro.value);
  });
}

}

Smartphone:

  • Device: SAMSUNG A32
  • OS: Android 13

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