react-native-background-actions: App Crashes with ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.sim.simsim/com.asterinet.react.bgactions.RNBackgroundActionsTask
“react-native”: “0.73.0”, “react-native-background-actions”: “^4.0.1”,
My App crashes as soon as it tries to start the foreground task with runtime exception.I have included android:foregroundServiceType to be dataSync and connectedDevice as the app uses ble and also needs to upload information.
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Above are the permissions included in the AndroidManifest.xml file and App uses
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
are the runtime permission.
Error which i get is E AndroidRuntime: java.lang.RuntimeException: Unable to start service com.asterinet.react.bgactions.RNBackgroundActionsTask@dee0a74 with Intent { cmp=com.sim.simsim/com.asterinet.react.bgactions.RNBackgroundActionsTask (has extras) }: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.sim.simsim/com.asterinet.react.bgactions.RNBackgroundActionsTask.
Crashed only on Android 14.
Checked the example in the library. App crashes and says the app has a bug.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 24
Same with me… works on dev mode, but crashing in Prod. Looks like the release build permission is:
<service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"/>and it should be:
<service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="dataSync"/>SOLUTION: Found a fork that fixed the issue (my app now works fine in production) https://www.npmjs.com/package/react-native-bg-actions