plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

fix(android_intent_plus): startForegroundService on SDK higher than 26

Open ViscousPot opened this issue 10 months ago • 1 comments

Description

Currently, when starting a foreground service or a non-foreground service while the application is in the background, the application fails with

not allowed to start service intent app is in background

This can be tested by trying to start a service where the application isn't in the foreground

  • Previous behaviour, it would give the error above
  • New behaviour sends the intent as expected and starts the service

The activity.startService logic has been removed as it isn't super necessary (applicationContext works fine) and it doesn't seem to work for startForegroundService when the target app is in the background, but I might be wrong here

Related Issues

No related issues exist for this

Checklist

  • [x] I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • [x] I titled the PR using Conventional Commits.
  • [x] I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • [x] All existing and new tests are passing.
  • [x] The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • [ ] Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • [x] No, this is not a breaking change.

ViscousPot avatar Mar 28 '25 01:03 ViscousPot

Thanks for looking into this! Could you add an example to the example that runs a foreground service? I'm trying to understand when this would be necessary, and I would like to test before approving. Also, the PR is set as Draft, not sure if that is intentional.

miquelbeltran avatar Apr 01 '25 11:04 miquelbeltran