Rapsssito / react-native-background-actions

React Native background service library for running background tasks forever in Android & iOS.
MIT License
819 stars 117 forks source link

App crashing on android 14 #241

Open divyaAtDelta opened 2 months ago

divyaAtDelta commented 2 months ago

I am performing background task to send users location to server after every 3 min. At the starting of the application i am asking for background location permission and while starting background service I am checking whether the permission has been given already or not?. If its given then only I am starting the background service. But, while starting permission was granted, but, now user put my application in the background and through settings app revoking the location permission. In this scenario application is crashing on android 14. But, on android 12 its working totally fine. Here I am sharing the crash report below, Fatal Exception: java.lang.RuntimeException: Unable to start service com.asterinet.react.bgactions.RNBackgroundActionsTask@59c59be with Intent { cmp=com.delta.the.runner/com.asterinet.react.bgactions.RNBackgroundActionsTask (has extras) mCallingUid=10544 }: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{a224dfd 27293:com.delta.the.runner/u0a544} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5134) at android.app.ActivityThread.-$$Nest$mhandleServiceArgs() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2481) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:257) at android.os.Looper.loop(Looper.java:368) at android.app.ActivityThread.main(ActivityThread.java:8839) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

Any help regarding this issue is highly appreciated.

glrahulborah commented 2 months ago

Facing the same issue

Yashi1919 commented 2 months ago

Can you tell me how we can get the crash report

glrahulborah commented 2 months ago

@divyaAtDelta The issue is related to prerequisite permissions required to start the foreground service. In your case, you have used "location" type and as per the Android documentation it requires at least one permission. Just check runtime prerequisites for location type.

divyaAtDelta commented 2 months ago

Can you tell me how we can get the crash report

I have got this from firebase console, as crashlytics is integrated in my project.

divyaAtDelta commented 2 months ago

@divyaAtDelta The issue is related to prerequisite permissions required to start the foreground service. In your case, you have used "location" type and as per the Android documentation it requires at least one permission. Just check runtime prerequisites for location type.

what permission you were missing previously, and now by adding that permission has fixed your issue, because in my case, the mentioned permission are already there in my manifest file.

glrahulborah commented 2 months ago

@divyaAtDelta The issue is related to prerequisite permissions required to start the foreground service. In your case, you have used "location" type and as per the Android documentation it requires at least one permission. Just check runtime prerequisites for location type.

what permission you were missing previously, and now by adding that permission has fixed your issue, because in my case, the mentioned permission are already there in my manifest file.

Permission in manifest is required and you need to grant the location permission to the app before starting the background action.

DiguinhoLNS commented 1 month ago

I try one solution and works well for now

on AndroidManifest.xml, add service for the backgroun service:

<service 
    android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" 
    android:foregroundServiceType="shortService"/>

on android/build.gradlew ,update do sdk 34:

buildToolsVersion = "34.0.0"
minSdkVersion = 21
compileSdkVersion = 34
targetSdkVersion = 34