I have upgrade the Android SDK project 30 to 31. Also i am using the the Android Beacon Library for scanning the the iBeacon.

Android 12 i am getting the frquently below crashes on 100% background application.

Caused by android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.beacon.android/org.altbeacon.beacon.service.BeaconService 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:6897) 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 org.altbeacon.beacon.BeaconManager.bindInternal(BeaconManager.java:438) at org.altbeacon.beacon.BeaconManager.autoBind(BeaconManager.java:1810) at org.altbeacon.beacon.BeaconManager.startMonitoring(BeaconManager.java:1136) at com.beacon.BeaconApplication.onCreate(BeaconApplication.kt:170) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1211) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7429) at android.app.ActivityThread.access$1700(ActivityThread.java:309) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2268) 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:8582) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:563) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)

Currently using Altbeacon library below version

implementation 'org.altbeacon:android-beacon-library:2.19.3'

Also, below Android SDK version 30, its working absolutely fine.

Thanks in Advance !

1

There are 1 answers

2
davidgyoung On

This is caused by a security change to Android 12. For apps targeting SDK 31, Android 12 now blocks starting a foreground service except in very specific circumstances. Typically, your app must visible on the screen to start a foreground service.

A solution to the specific problem in the Android Beacon Library has been released in a subsequent library version. See the solution discussed here.

See here for a discussion of the bigger picture issue of using Foreground Services