-
-
Notifications
You must be signed in to change notification settings - Fork 266
ForegroundServiceStartNotAllowedException (Android 12) #400
Comments
Should be fixed in |
This is still occurring. Just launched with 1.4.1 and I'm getting these errors on Android 12. I think it's relevant that I recently upgraded my compile target to SDK 31.
I'm doing some research, in the meanwhile @bradleyflood would you mind reopening this? |
One suggestion I'm seeing is to pass |
Sure @elliotdickison thanks. Can you test that idea and if it works create a PR? Cheers |
Unfortunately I think it's going to be more complicated than that. Here are the results of my research so far:
|
@elliotdickison You might be better off using https://github.com/doublesymmetry/react-native-track-player |
I did some further investigation, updated the project and added some of @elliotdickison suggestions in #407 I am also not sure, if about the following two:
Leaving some links here that might be related and could help: |
We have the same issues but unfortunately adding the flag to the manifest does not help. |
By wrapping the whole problematic code-block into try-catch (instead of just single parts, excluding the crashing line) seem to fix the crashes (not the issue itself) see commit bb1b1e9. I have updated a Prod-App with this version swrlab/react-native-music-control#v1.5.1 and no more If anyone could verify this, we could try to get the PR merged and switch back to the original source. |
Yes, in this why crashes can be fixed, the problem is that music cannot be listened in background when this issue happens. The app will not crash anymore but music cannot be played while the app is in background, the definitive fix would be a workaround to avoid the exception at all. There is a new version of https://github.com/doublesymmetry/react-native-track-player that they said should have fixed the issue, it is in kotlin though and it seems to use a slightly different API for the MusicService, don't know if we can take inspiration from it for the definitive fix in some way. |
Problem:
I am getting lots of
ForegroundServiceStartNotAllowedException
from Devices with Android 12.It seems to happen on
NotificationService.forceForeground()
inMusicControlNotification.java:215
It might likely relate to Android 12 Foreground Service restrictions (from Android Docs):
Possible solution:
Add a service entry to AndroidManifest.xml with android:foregroundServiceType = mediaPlayback attribute.
I cannot verify this fix is working, as I don't have an Android 12 device to test it myself...
Description
Platform ?
The text was updated successfully, but these errors were encountered: