-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App Crashes with ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.sim.simsim/com.asterinet.react.bgactions.RNBackgroundActionsTask #251
Comments
@Rapsssito Please let me know if i am missing anything. Thankyou in Advance. |
@muramidaza any solution? I facing the same issue. |
Hello,
Thankyou for responding.
"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
***@***.*** 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.
…On Tue, Dec 3, 2024 at 10:19 AM Iván González ***@***.***> wrote:
@smitha-2020 <https://github.com/smitha-2020> which version are you using?
—
Reply to this email directly, view it on GitHub
<#251 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARIKKRU3EVX7435XSWHHPOL2DVSSJAVCNFSM6AAAAABS25YVGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJTHAZTINJSGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Try with this Hi! 👋 Firstly, thanks for your work on this project! 🙂 Today I used patch-package to patch Here is the diff that solved my problem: diff --git a/node_modules/react-native-background-actions/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java b/node_modules/react-native-background-actions/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
index 9900fc0..2fc7ceb 100644
--- a/node_modules/react-native-background-actions/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
+++ b/node_modules/react-native-background-actions/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
@@ -42,9 +42,9 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
}
final PendingIntent contentIntent;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
- contentIntent = PendingIntent.getActivity(context,0, notificationIntent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT);
+ contentIntent = PendingIntent.getActivity(context,0, notificationIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
+ contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else { This issue body was partially generated by patch-package. |
Hello Iván,
I tried changing the lines in the RNBackgroundActionTask
But the error still exists and the app crashes whenever it tries to start
the background.
Thankyou.
On Tue, Dec 3, 2024 at 11:24 AM smitha kamath ***@***.***>
wrote:
… Hello,
Thankyou for responding.
"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
***@***.*** 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.
On Tue, Dec 3, 2024 at 10:19 AM Iván González ***@***.***>
wrote:
> @smitha-2020 <https://github.com/smitha-2020> which version are you
> using?
>
> —
> Reply to this email directly, view it on GitHub
> <#251 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ARIKKRU3EVX7435XSWHHPOL2DVSSJAVCNFSM6AAAAABS25YVGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJTHAZTINJSGQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***
> com>
>
|
Could you please share the error that you get but from Android Studio? |
Hello,
I am using the Android 14 device connected to the usb.
I cannot use the simulator as iam working with ble.
12-03 12:10:43.625 19432 19432 E AndroidRuntime: FATAL EXCEPTION: main
12-03 12:10:43.625 19432 19432 E AndroidRuntime: Process: com.sim.simsim,
PID: 19432
12-03 12:10:43.625 19432 19432 E AndroidRuntime:
java.lang.RuntimeException: Unable to start service
***@***.*** 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
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5286)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2531)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Handler.dispatchMessage(Handler.java:106)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Looper.loopOnce(Looper.java:230)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Looper.loop(Looper.java:319)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.ActivityThread.main(ActivityThread.java:8919)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
java.lang.reflect.Method.invoke(Native Method)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: Caused by:
android.app.ForegroundServiceStartNotAllowedException:
Service.startForeground() not allowed due to mAllowStartForeground false:
service com.sim.simsim/com.asterinet.react.bgactions.RNBackgroundActionsTask
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Parcel.readParcelableInternal(Parcel.java:4882)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Parcel.readParcelable(Parcel.java:4864)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Parcel.createExceptionOrNull(Parcel.java:3064)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Parcel.createException(Parcel.java:3053)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Parcel.readException(Parcel.java:3036)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.os.Parcel.readException(Parcel.java:2978)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7234)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.Service.startForeground(Service.java:775)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
com.asterinet.react.bgactions.RNBackgroundActionsTask.onStartCommand(RNBackgroundActionsTask.java:93)
12-03 12:10:43.625 19432 19432 E AndroidRuntime: at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5268)
On Tue, Dec 3, 2024 at 12:06 PM Iván González ***@***.***>
wrote:
… Hello Iván, I tried changing the lines in the RNBackgroundActionTask But
the error still exists and the app crashes whenever it tries to start the
background. Thankyou. On Tue, Dec 3, 2024 at 11:24 AM smitha kamath *@*.
*> wrote: … <#m_7878177758717104091_> Hello, Thankyou for responding.
"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.
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 @.* 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. On Tue, Dec 3, 2024 at 10:19 AM Iván González
*@*.*> wrote: > @smitha-2020 <https://github.com/smitha-2020>
https://github.com/smitha-2020 <https://github.com/smitha-2020> which
version are you > using? > > — > Reply to this email directly, view it on
GitHub > <#251 (comment)
<#251 (comment)>>,
> or unsubscribe >
https://github.com/notifications/unsubscribe-auth/ARIKKRU3EVX7435XSWHHPOL2DVSSJAVCNFSM6AAAAABS25YVGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJTHAZTINJSGQ
<https://github.com/notifications/unsubscribe-auth/ARIKKRU3EVX7435XSWHHPOL2DVSSJAVCNFSM6AAAAABS25YVGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJTHAZTINJSGQ>
> . > You are receiving this because you were mentioned.Message ID: > @.*
> com> >
Could you please share the error that you get but from Android Studio?
—
Reply to this email directly, view it on GitHub
<#251 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARIKKRS6WA2QEK4N323NQKD2DV7CPAVCNFSM6AAAAABS25YVGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJUGA4TOOBRHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
Did you request notification permission this way? It is required on Android 13+ await PermissionsAndroid.request("android.permission.POST_NOTIFICATIONS"); |
I have added it this way
const requestBLEPermission = async () => {
if (Platform.OS !== 'android') {
return;
}
if (Platform.Version >= 31) {
PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
]).then((result) => {
if (result) {
console.debug(
'[handleAndroidPermissions] User accepts runtime permissions android 12+',
);
} else {
console.error(
'[handleAndroidPermissions] User refuses runtime permissions android 12+',
);
}
});
}
};
On Tue, Dec 3, 2024 at 1:10 PM smitha kamath ***@***.***>
wrote:
… ok let me remove it
On Tue, Dec 3, 2024 at 12:51 PM Iván González ***@***.***>
wrote:
> Did you request notification permission this way? It is required on
> Android 13+
>
> await PermissionsAndroid.request("android.permission.POST_NOTIFICATIONS");
>
> —
> Reply to this email directly, view it on GitHub
> <#251 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ARIKKRSJGLL54XZCZH52B332DWEMZAVCNFSM6AAAAABS25YVGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJUGIYDINRYHA>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***
> com>
>
|
Is there any settings or configuration taht needs to be added as specified
by this https://reactnative.dev/docs/headless-js-android
On Tue, Dec 3, 2024 at 1:19 PM smitha kamath ***@***.***>
wrote:
… I have added it this way
const requestBLEPermission = async () => {
if (Platform.OS !== 'android') {
return;
}
if (Platform.Version >= 31) {
PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
]).then((result) => {
if (result) {
console.debug(
'[handleAndroidPermissions] User accepts runtime permissions android 12+',
);
} else {
console.error(
'[handleAndroidPermissions] User refuses runtime permissions android 12+',
);
}
});
}
};
On Tue, Dec 3, 2024 at 1:10 PM smitha kamath ***@***.***>
wrote:
> ok let me remove it
>
> On Tue, Dec 3, 2024 at 12:51 PM Iván González ***@***.***>
> wrote:
>
>> Did you request notification permission this way? It is required on
>> Android 13+
>>
>> await PermissionsAndroid.request("android.permission.POST_NOTIFICATIONS");
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#251 (comment)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/ARIKKRSJGLL54XZCZH52B332DWEMZAVCNFSM6AAAAABS25YVGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJUGIYDINRYHA>
>> .
>> You are receiving this because you were mentioned.Message ID:
>> ***@***.***
>> com>
>>
>
|
Do we need anather library react-native-foreground-service?
compileSdkVersion = 34 |
@BagasNS could you look into this issue please. |
Had the same issue and fixed by adding these lines from here: |
Thankyou @rokanost. Tried it. Its still gives the same problem. Crashes as soon as the background task starts. |
I'm also facing this issue on the release Store, on both android 13 and android 14 |
@patphantuan251 Did you happen to solve it ? |
I tried cleaning all cache, then following @rokanost and it worked on my device. However, after pushing to the store, the problem still occurs every day with a few users (about 10 people) and I still haven't been able to fix it. |
@patphantuan251 what is the version of react native and react-native-background-actions you are using? and also what are the foregroundServiceTypes you are targetting? |
Same with me.. works on dev mode, but crashing in Prod.
and it should be:
SOLUTION: |
"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.
Above are the permissions included in the AndroidManifest.xml file and App uses
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.
The text was updated successfully, but these errors were encountered: