Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

Exception ocurring leading to crash: android.app.ForegroundServiceStartNotAllowedException

Open imyourdeveloperhere opened this issue 9 months ago • 9 comments

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 avatar Oct 29 '23 10:10 imyourdeveloperhere

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 avatar Feb 01 '24 14:02 omerb09

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

omerb09 avatar Feb 05 '24 13:02 omerb09

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

vbuberen avatar Feb 14 '24 10:02 vbuberen

Thanks @vbuberen this version seems to work

omerb09 avatar Feb 14 '24 12:02 omerb09

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 https://github.com/florent37/Flutter-AssetsAudioPlayer/issues/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.

vbuberen avatar Feb 14 '24 12:02 vbuberen

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.

omerb09 avatar Feb 24 '24 08:02 omerb09

@vbuberen @omerb09 can you please share me version

mjjoshi avatar Apr 22 '24 05:04 mjjoshi

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.

vbuberen avatar Apr 22 '24 14:04 vbuberen

@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.

omerb09 avatar May 03 '24 13:05 omerb09

@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.

Same, in review now.

vlowe85 avatar Jul 14 '24 13:07 vlowe85

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

This resolved the crash on Android 14 for me. Is there a reason this isn't released yet? Seems to have been open a while. Curious as i have has to use in production.

vlowe85 avatar Jul 14 '24 13:07 vlowe85

Is there a reason this isn't released yet? Seems to have been open a while. Curious as i have has to use in production.

I am not the maintainer of this package, so can't release the fix.

vbuberen avatar Jul 15 '24 08:07 vbuberen