Skip to content
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

Exception ocurring leading to crash: android.app.ForegroundServiceStartNotAllowedException #813

Open
imyourdeveloperhere opened this issue Oct 29, 2023 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@imyourdeveloperhere
Copy link

imyourdeveloperhere commented Oct 29, 2023

My Flutter Version: 3.7.0

Lib Version: 3.1.1

Platform Android

Platform : Android

Describe the bug

Occurring the Android 12 & 13 majorly, issue is the foreground.

com.github.florent37.assets_audio_player.notification.NotificationService.displayNotification

android.app.ForegroundServiceStartNotAllowedException

A clear and concise description of what the bug is.

Exception:

Exception android.app.ForegroundServiceStartNotAllowedException:
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:54)
at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel (ForegroundServiceStartNotAllowedException.java:50)
at android.os.Parcel.readParcelable (Parcel.java:3334)
at android.os.Parcel.createExceptionOrNull (Parcel.java:2421)
at android.os.Parcel.createException (Parcel.java:2410)
at android.os.Parcel.readException (Parcel.java:2393)
at android.os.Parcel.readException (Parcel.java:2335)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground (IActivityManager.java:7343)
at android.app.Service.startForeground (Service.java:733)
at com.github.florent37.assets_audio_player.notification.NotificationService.displayNotification (NotificationService.java)
at com.github.florent37.assets_audio_player.notification.NotificationService.access$displayNotification (NotificationService.java)
at com.github.florent37.assets_audio_player.notification.NotificationService$displayNotification$1.invokeSuspend (NotificationService.java)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java)
at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.java)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:210)
at android.os.Looper.loop (Looper.java:299)
at android.app.ActivityThread.main (ActivityThread.java:8309)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1038)
Caused by android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked (ActiveServices.java:1894)
at com.android.server.am.ActiveServices.setServiceForegroundLocked (ActiveServices.java:1403)
at com.android.server.am.ActivityManagerService.setServiceForeground (ActivityManagerService.java:12338)
at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:3318)
at com.android.server.am.ActivityManagerService.onTransact (ActivityManagerService.java:2559)

@imyourdeveloperhere imyourdeveloperhere added the bug Something isn't working label Oct 29, 2023
@imyourdeveloperhere imyourdeveloperhere changed the title Excetion ocurring leading to crash Exception ocurring leading to crash Oct 29, 2023
@imyourdeveloperhere imyourdeveloperhere changed the title Exception ocurring leading to crash Exception ocurring leading to crash: android.app.ForegroundServiceStartNotAllowedException Oct 29, 2023
@omerb09
Copy link

omerb09 commented Feb 1, 2024

I'm getting the same error. Is there any progress?

  • Flutter version: 3.10.6,
  • Assets Audio Player version : 3.1.1,
  • Only Android 14 (Api 34) issue,

FATAL EXCEPTION: main
Process: com.hayt****, PID: 12092
java.lang.SecurityException: Starting FGS with type mediaPlayback callerApp=ProcessRecord{c60496 12092:com.hay****/u0a192} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK]
at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.os.Parcel.readException(Parcel.java:2966)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6761)
at android.app.Service.startForeground(Service.java:775)
at com.github.florent37.assets_audio_player.notification.NotificationService.displayNotification(NotificationService.kt:349)
at com.github.florent37.assets_audio_player.notification.NotificationService.access$displayNotification(NotificationService.kt:32)
at com.github.florent37.assets_audio_player.notification.NotificationService$displayNotification$1.invokeSuspend(NotificationService.kt:148)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)

@omerb09
Copy link

omerb09 commented Feb 5, 2024

For my application this method worked. I just added permission to the manifest. "android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
https://stackoverflow.com/a/76943772/16647487

@vbuberen
Copy link
Contributor

Thanks to @omerb09 for pointing on a solution. I have made a PR which was already merged, so would suggest to try and use the plugin but point to that commit in master:

  assets_audio_player:
    git:
      url: https://github.com/florent37/Flutter-AssetsAudioPlayer.git
      ref: 91638830570e5e3c2212d04fd99b8d3b60380dd3

@omerb09
Copy link

omerb09 commented Feb 14, 2024

Thanks @vbuberen this version seems to work

@vbuberen
Copy link
Contributor

Oh, didn't expect that fast feedback. In such case could you tell me if it works Ok for you on other Android versions?
Because I feel that this issue is connected with #803 but I only have a device with Android 14 where I can't reproduce #803 now even though I could in September. I am just curios if this change for Android 14 that I made with my PR somehow also affected the issue on Android 13 due to that missing permission.

@omerb09
Copy link

omerb09 commented Feb 24, 2024

I published my application with the version you mentioned for my test users. I didn't catch any errors with this issue. However, they threw out the error in #803. All errors occurred while the application was in the background. It also happened on Android 13 and 14.

@mjjoshi
Copy link

mjjoshi commented Apr 22, 2024

@vbuberen @omerb09 can you please share me version

@vbuberen
Copy link
Contributor

can you please share me version
There is no version. You need to use version from master. It is specified a few messages above how to add a dependency pointing to the right commit.

@omerb09
Copy link

omerb09 commented May 3, 2024

@vbuberen Now you are using android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK in the new version of the package. Google Play requires us to explain with a video why we use this permission for Android 14 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants