-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
android.app.ForegroundServiceStartNotAllowedException - Service.startForeground() not allowed due to mAllowStartForeground false #2231
Comments
i'm also experiencing this issue |
duplicate of #2184 |
We can't just ask/expect users to disable battery optimizations, it's our problem as the devs, not the user's |
this is a UX improvement set by google since android12. as much as youd like to call this a dev problem unfortunately there aint many options other than listed here: realistically i see 4 options: SYSTEM_ALERT_WINDOW given the flutter folks recommended the first two and didnt implement the latter two, i dont have high hopes these will turn out working right, but if u do pls submit a pr |
I posted a solution to this here: #2198 - I'm trying to see if we can work it into a patch for RNTP this week - all the code is there that keeps the app awake while audio is playing, but right now it is just app changes and not a pluggable part of RNTP. |
i wonder if wakeLock has any effect on context.startForegroundService?
theorrtically it just keeps the background service alive
also not sure how generalizable this should be since Google's against this
for battery life reasons
https://developer.android.com/develop/background-work/background-tasks/scheduling/wakelock#cpu
but all in all, its all googles fault
…On Thu, Jan 4, 2024, 12:58 PM Justin Handley ***@***.***> wrote:
I posted a solution to this here: #2198
<#2198>
- I'm trying to see if we can work it into a patch for RNTP this week - all
the code is there that keeps the app awake while audio is playing, but
right now it is just app changes and not a pluggable part of RNTP.
—
Reply to this email directly, view it on GitHub
<#2231 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZMOVVRAEGEY7KOOFRKOFQ3YM4JXPAVCNFSM6AAAAABBIXSQVKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZXG42TCNJXGY>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Hello, anyone managed to fix this issue, we are also experiencing this issue on production. |
It isn't simple, but I believe that it is related to this: #2198 - the workaround I put in place there keeps the device from sleeping while audio is playing - it does use more battery, but it gets away from having to ask people toadjust their battery settings. We are in production and are no longer seeing this error. |
Hi... |
okay, I'm willing to investigate further, there's clearly something wrong with how the MusicService is started. I'm not an android expert but if I just observe what's in dev options -> running services: |
Thanks for offering to investigate — I was hoping to look more into it too, but I've been busy with work / it doesn't look like I'll be getting free time any time soon. But If anayone has figured a solid way to repro, I'm happy to try out any PRs. |
ok. For those interested: enable dev options and watch the RNTP app in the running state and cache state. When playing the process should have musicService attached. when the app goes into the cache state, notification posted with id=1, ongoing=false will be triggered and foreground service is therefore lost. when the app is resumed, the active foreground service is no longer attached to the activity, or there's something buggy about this that AppKilledBehavior will no longer connect to the current MusicService; now swiping to close app will not kill playback if configured. Can MusicService even be kept as foreground when app goes into cached? it doesnt seem like so Also I have my app on unrestricted battery for a good 5 hours, and it used ~1% battery and ~250MB RAM; AIMP on the other hand used 80MB RAM and ~0.5% battery. I dont think its unrealistic to ask for unrestricted battery use. |
if anyone can disable stopForeground like this |
We saw a spike in this crash starting yesterday. They're all Android 14 on Google Pixel devices (6a and 8). Not sure exactly how to create a minimal reproducible sample, but maybe see if it's easier to reproduce on one of those devices if you have one available. |
ur welcome to try |
@dcvz @lovegaoshi Anything on this seems many users getting affected, today only 5 users have the same issue. |
It is happening in Android 14 too, see attached, I can give you log |
you're triggering this via setupPlayer? so this happens at app start up? |
As per the stacktrace and the session log we have, it doesn't crash at startup, but when it tries to play audio for the first time
|
the trace log specifically occurs at MM.setupPlayer which is the RN module, where TP.setupPlayer calls it, not when audio is first played; do you use await TP.setupPlayer? and why is your app no longer in foreground when the first audio plays? |
Yes using So basically the setup is like |
so your app reliably crushes with this exception on android 14? |
No, it doesn't get called twice. |
then when is your TP.setupPlayer called? if its truly on component render your app cannot be in background at all |
The app can play Audio in the background but once the Audio has been started, not before. |
wdym play audio in the background, via the notification panel? |
I am breaking configurations in steps as follows Step1
Step2
Step3
Let me know where I am doing wrong? Thanks. |
@lovegaoshi Anything on above, the issue still exist? Thanks. |
unless you can reproduce with the **example app** reliably.
i dont see this error what so ever with sentry so you're kinda on your own,
or pay to consult with ds
…On Thu, Apr 4, 2024, 7:51 PM Ved Prakash ***@***.***> wrote:
wdym play audio in the background, via the notification panel? i'm still
not clear why/how youre triggering TP.setupPlayer. if you put a console.log
within TP.setupPlayer theoretically you should see it once upon app start,
thats it. since youre saying it doesnt fire twice but this is observed with
the traceback, something doesnt add up
I am breaking configurations in steps as follows
Step1 index.js <=== Entry point of the Application
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
Step2 Inside App.js
import TrackPlayer from 'react-native-track-player';
import {PlaybackService} from './playbackservice';
TrackPlayer.registerPlaybackService(() => PlaybackService);
export default class App extends Component {
constructor(props) {
super(props);
}
async componentDidMount() { <=== This is called once in the whole lifecycle of the Application
await TrackPlayer.setupPlayer();
}
render(){
...
}
}
Step3 In a Different screen say ScreenA.js on button click
async onPlayAction = (e) => {
await TrackPlayer.reset();
await TrackPlayer.add(tracks);
await TrackPlayer.play();
}
Let me know where I am doing wrong? Thanks.
@lovegaoshi <https://github.com/lovegaoshi> Anything on above, the issue
still exist? Thanks.
—
Reply to this email directly, view it on GitHub
<#2231 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZMOVVSZEKPV542Z6D755YTY3YGTFAVCNFSM6AAAAABBIXSQVKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZYG4YTANJQGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Has anyone found a way to fix or somehow get around this error? I'm seeing these identical errors inPlay Store and Firebase Crashlytics for Android 14. Using react-native-track-player 4.1.1. |
Same here!! |
any solution for this ? 😢 |
I have the same issue |
Same issue await TrackPlayer.setupPlayer(); |
I fixed crash by add permission "android.permission.FOREGROUND_SERVICE_LOCATION" , who have the same quetions can find what permission you need to add: https://developer.android.com/reference/android/Manifest.permission |
Has anyone else also fixed the crash by adding that permission? Wouldnt it make more sense to use "FOREGROUND_SERVICE_MEDIA_PLAYBACK" and not location? Or does it work because "FOREGROUND_SERVICE_LOCATION" indirectly fixes the problem by keeping the app active? |
Describe the Bug
Fatal Exception: java.lang.RuntimeException
Unable to start service com.doublesymmetry.trackplayer.service.MusicService@43cf99 with null: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.app.android/com.doublesymmetry.trackplayer.service.MusicService
Steps To Reproduce
TBH it did not happen to me on debug, but it seems that is happening to my users in production. I have reports from Firebase Crashlytics.
OS: macOS 13.5.2
CPU: (8) arm64 Apple M1
react-native: ^0.68.0 => ^0.68.0
xCode: 15(15A240d)/usr/bin/xcodebuild
Using react-native-track-player@^4.0.1
This is happen on real devices(All Google phone), most of them android 14.
The text was updated successfully, but these errors were encountered: