-
Notifications
You must be signed in to change notification settings - Fork 61
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
Crash on android when running in background #91
Comments
Facing the same issue |
Facing the same issue also. anyone found solution on this issue? |
I've noticed this issue too (as Android 12 onward doesn't allow starting services in the background). I noticed that if the user disables battery optimisation it seems to resolve the issue, however I think music apps are not allowed to call ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS and ask users to do this. Thanks for the try-catch workaround suggestions :) 👍🏼 |
I don't really think so as it's not a proper fix. Proper fix would require an error callback so that application can react. empty try-catch is just a hack we used so that our app doesn't crash as we have guaranteed in our code, music controls are created only when app is in foreground |
@ghenry22 Would some android specific method in plugin API, e.g. "setNotificationCreateErrorCallback" or something like that be considered an acceptable fix? I could create a PR with this if this approach is ok with you |
Scenario:
The cordova app is set to KeepRunning=true and app is in background. one track stops playing, next one loads automatically, so we want to update the mediaControls (by calling the create method), we however receive following crash:
It's because the app attempts to start foreground service from background app, which is not allowed in newer versions of android (i guess 12+).
This is however not required if there is an already active music controls notification existing.
We temporarily tackled this by wrapping the setForeground call into try-catch and everything works fine, I however understand this would need a more generic approach. (e.g. some global on error callback or something like this)....or checking if a notification is active and if is, not attempting to restart....either way - cordova plugin should not crash the app.
Could this somehow be fixed or is it out of scope of your plugin usage?
The text was updated successfully, but these errors were encountered: