Closed JoelFickson closed 2 months ago
Thank you, but isn't this unnecessary since it is declared in the manifest?
Thank you, but isn't this unnecessary since it is declared in the manifest? Actually, there is a need for that since Android 14:
Check https://developer.android.com/about/versions/14/changes/fgs-types-required#permission-for-fgs-type
I am was testing it on Android 14 and the media notification doesn't show up on my Google Pixel 7 Pro and even emulator on Pixel 8 Pro.
My question was specifically about whether doing this at runtime is necessary "given" that this is already specified in the manifest. In other words, are you wanting to change this because you believe the manifest approach is wrong and/or doesn't work, or are you wanting to change this because you think it is better practice to do it at runtime rather than in the manifest?
@ryanheise its because the current approach doesnt work. As I referenced the link to the docs, there needs to be this runtime check. Seems the current approach works for Android <=13 but not >13. We need both approaches.
That would seems surprising, since even the page you linked to says this:
If the foreground service type is not specified in the call, the type defaults to the values defined in the manifest. If you didn't specify the service type in the manifest, the system throws MissingForegroundServiceTypeException.
There is also this part.
I am not only just trying to propose these changes, I'm proposing because I do run into the following error:
android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{aa0db08 4727:com.xxx.app/u0a202} targetSDK=34 W/System.err( 4727): at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53) W/System.err( 4727): at android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
Then let's put aside that is a better practice because that is really a lower priority that pointing out that the current approach doesn't work. I am saying I highly doubt that the current approach doesn't work because the documentation says it does work, and people are using it successfully in Android 14.
If you're saying you've already put it in the manifest and yet it doesn't work, can you perhaps share your manifest so that I can see it?
My bad! We can close the issue. This seems to work.
android:name="com.ryanheise.audioservice.AudioService"
android:exported="true"
android:foregroundServiceType="mediaPlayback">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>```
chore: add support for android 14 and above to start foreground services.
If there's an open issue your PR is fixing, please list it here.
Pre-launch Checklist
minor
branch OR my change is breaking and lands inmajor
branch.pubspec.yaml
according to the pub versioning philosophy.* DESCRIPTION OF YOUR CHANGE (@your-git-username)
).///
).dart analyze
.dart format
.flutter test
and all tests are passing.