Users crashing because of Service.startForeground() not allowed due to mAllowStartForeground false only on Anddroid 14

230 Views Asked by At

I just released an update targeting API 34 and suddenly I'm getting this exception and it is happening 100% only on Android 14 devices.

Caused by android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service mypackage.myservice
       at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
       at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
       at android.os.Parcel.readParcelableInternal(Parcel.java:4882)
       at android.os.Parcel.readParcelable(Parcel.java:4864)
       at android.os.Parcel.createExceptionOrNull(Parcel.java:3064)
       at android.os.Parcel.createException(Parcel.java:3053)
       at android.os.Parcel.readException(Parcel.java:3036)
       at android.os.Parcel.readException(Parcel.java:2978)
       at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7214)
       at android.app.Service.startForeground(Service.java:862)

    

My code didn't really change for the startForeground call.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        service.startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
    }else{
        service.startForeground(NOTIFICATION_ID, notification);
    }

Also, this is only happening on crashlytics, I haven't been able to reproduce it myself, the service starts fine for me.

And yes I have gone through the Play Store App content declaration for foreground services and it was accepted.

Any idea what the issue could be?

0

There are 0 best solutions below