Android 12 - Samsung Accessory SDK can not start foreground service

I am trying to update my Samsung accessory provider app to target Android 12 (API 31)

com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver tries to bring up the service but it can not.
As described here:

Android 12 does not allow starting a foreground service except a few special cases.

So my service crash with this error:

2022-04-05 15:06:28.927 28310-28310/com.mycom.gear E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycom.gear, PID: 28310
java.lang.RuntimeException: Unable to start receiver com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.mycom.gear/.service
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4766)
at android.app.ActivityThread.access$1800(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2288)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)
Caused by: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.mycom.gear/.service
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:3345)
at android.os.Parcel.createExceptionOrNull(Parcel.java:2432)
at android.os.Parcel.createException(Parcel.java:2421)
at android.os.Parcel.readException(Parcel.java:2404)
at android.os.Parcel.readException(Parcel.java:2346)
at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:6914)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1926)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1892)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:796)
at com.samsung.android.sdk.accessory.m.a(Unknown Source:51)
at com.samsung.android.sdk.accessory.m.a(Unknown Source:2)
at com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver.onReceive(Unknown Source:72)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4757)
at android.app.ActivityThread.access$1800(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2288)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:771)
at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:679)
at com.android.server.am.ActivityManagerService.startService(ActivityManagerService.java:14013)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2943)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3034)

is there a solution to this within Samsung accessory sdk ?
what can I do ?

Hi Ilker,

I’d suggest you create a Developer Support Request That is all I can think of.

Ron

thank you.
I’ll do that. But the forums are losing its value day by day.
I had a few issues recently , and for none of them I could get a solution…

Hi Ilker,
I saw you have submitted this issue on the Developer Support channel. We are currently investigating this issue.

Thank you

Yes I submitted but the first answer is weird. It says:
" Galaxy Accessory SDK is not supported for API 31. Currently there is no plan to upgrade the Galaxy Accessory SDK. We recommend you to not to update the Target SDK as of now."

However, Google Play Policy says that we have to upgrade our apps to Android 12 (API 31) until 2023

If we can’t update, companion apps will not be available to new users for download.