Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Dec 15, 2023 · 0 comments
Open

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

ghost opened this issue Dec 15, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Dec 15, 2023

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
@ghost ghost added the bug Something isn't working label Dec 15, 2023
@ghost ghost assigned JulianAssmann Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant