Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting FGS with type none callerApp=ProcessRecord{c23a512 15473:mypackage/u0a350} targetSDK=34 has been prohibited

I'm getting this exception when scheduling a work manager task.

android.app.InvalidForegroundServiceTypeException: Starting FGS with type none callerApp=ProcessRecord{c23a512 15473:mypackage/u0a350} targetSDK=34 has been prohibited

I added

    <service
        android:name="androidx.work.impl.foreground.SystemForegroundService"
        android:foregroundServiceType="dataSync"
        android:exported="false"
        android:stopWithTask="false"
        tools:node="merge"/>

And the issue is still happening.

I then updated from work manager from 2.7.0 to 2.9.0 and still didn't help.

I'm at a bit of a loss as to what the issue could be. The exception is happening at at androidx.work.impl.foreground.SystemForegroundService$Api31Impl.startForeground(SystemForegroundService.java:193)

I've also checked and the merged manifest does have my stuff.

Does anyone know what the issue could be?

like image 559
casolorz Avatar asked Sep 02 '25 17:09

casolorz


1 Answers

I must have missed a step. I had to add ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC to the ForegroundInfo constructor.

Code:-

val foregroundInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            ForegroundInfo(Random.nextInt(), notification,ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
        } else {
            ForegroundInfo(Random.nextInt(), notification)
        }
like image 75
casolorz Avatar answered Sep 05 '25 14:09

casolorz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!