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

Not working with Android 14 #200

Closed caleblawrence closed 5 months ago

caleblawrence commented 12 months ago

I can't get this package to work on Android 14. It's causing the app to crash with this error:

2023-11-14 14:17:48.728 30138-30138/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.compassionclips, PID: 30138
    java.lang.RuntimeException: Unable to start service com.asterinet.react.bgactions.RNBackgroundActionsTask@eccf065 with Intent { cmp=com.compassionclips/com.asterinet.react.bgactions.RNBackgroundActionsTask (has extras) }: java.lang.IllegalArgumentException: com.compassionclips: Targeting U+ (version 34 and above) disallows creating or retrieving a PendingIntent with FLAG_MUTABLE, an implicit Intent within and without FLAG_NO_CREATE and FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for security reasons. To retrieve an already existing PendingIntent, use FLAG_NO_CREATE, however, to create a new PendingIntent with an implicit Intent use FLAG_IMMUTABLE.
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4839)
        at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at android.app.ActivityThread.main(ActivityThread.java:8177)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
     Caused by: java.lang.IllegalArgumentException: com.compassionclips: Targeting U+ (version 34 and above) disallows creating or retrieving a PendingIntent with FLAG_MUTABLE, an implicit Intent within and without FLAG_NO_CREATE and FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for security reasons. To retrieve an already existing PendingIntent, use FLAG_NO_CREATE, however, to create a new PendingIntent with an implicit Intent use FLAG_IMMUTABLE.
        at android.os.Parcel.createExceptionOrNull(Parcel.java:3061)
        at android.os.Parcel.createException(Parcel.java:3041)
        at android.os.Parcel.readException(Parcel.java:3024)
        at android.os.Parcel.readException(Parcel.java:2966)
        at android.app.IActivityManager$Stub$Proxy.getIntentSenderWithFeature(IActivityManager.java:6568)
        at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:549)
        at android.app.PendingIntent.getActivity(PendingIntent.java:530)
        at android.app.PendingIntent.getActivity(PendingIntent.java:494)
        at com.asterinet.react.bgactions.RNBackgroundActionsTask.buildNotification(RNBackgroundActionsTask.java:45)
        at com.asterinet.react.bgactions.RNBackgroundActionsTask.onStartCommand(RNBackgroundActionsTask.java:89)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4821)
        at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:205) 
        at android.os.Looper.loop(Looper.java:294) 
        at android.app.ActivityThread.main(ActivityThread.java:8177) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 
xi-co commented 11 months ago

SAME HERE

System: OS: macOS 14.2 CPU: (8) arm64 Apple M1 Memory: 83.19 MB / 8.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 18.2.0 path: ~/.nvm/versions/node/v18.2.0/bin/node Yarn: Not Found npm: version: 8.9.0 path: ~/.nvm/versions/node/v18.2.0/bin/npm Watchman: version: 2023.12.04.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: Not Found SDKs: iOS SDK: Not Found Android SDK: API Levels:

DZamataev commented 11 months ago

Faced the same issue. Try setting your targetSdkVersion to 33. image

ng-ha commented 10 months ago

Faced the same issue. Try setting your targetSdkVersion to 33. image

downgrade isn't good answer. Do you have another solution?

devtyty commented 10 months ago

@ng-ha you can use this patch for android 14

index b67ef4d..cf8cab4 100644
--- a/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
+++ b/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions">
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <application>
-        <service android:name=".RNBackgroundActionsTask"/>
+        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="shortService"/>
     </application>
 </manifest>
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 315dbd4..ccba9a6 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
@@ -40,8 +40,11 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
             //as RN works on single activity architecture - we don't need to find current activity on behalf of react context
             notificationIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
         }
+
         final PendingIntent contentIntent;
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+        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);
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
ng-ha commented 10 months ago

@ng-ha you can use this patch for android 14

index b67ef4d..cf8cab4 100644
--- a/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
+++ b/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions">
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <application>
-        <service android:name=".RNBackgroundActionsTask"/>
+        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="shortService"/>
     </application>
 </manifest>
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 315dbd4..ccba9a6 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
@@ -40,8 +40,11 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
             //as RN works on single activity architecture - we don't need to find current activity on behalf of react context
             notificationIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
         }
+
         final PendingIntent contentIntent;
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+        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);
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

this worked for me. Thank you!

nop33 commented 8 months ago

I also ugpraded to API Level 34 and applied the patch from above. But now, after about 160 seconds of having the app in the bg, I get this message. Did any of you face that?

image
nop33 commented 8 months ago

I guess the problem is the "shortService"

devtyty commented 8 months ago

I guess the problem is the "shortService"

You can try with this pr #208

AftabUfaq commented 8 months ago

I guess the problem is the "shortService"

You can try with this pr #208

I have added that but still have an issue with this.

java.lang.RuntimeException: Unable to start service com.asterinet.react.bgactions.RNBackgroundActionsTask@e9a8a1a with Intent { cmp=com.appauthmobile/com.asterinet.react.bgactions.RNBackgroundActionsTask (has extras) }: android.app.MissingForegroundServiceTypeException: Starting FGS without a type callerApp=ProcessRecord{3b2b00c 12531:com.appauthmobile/u0a513} targetSDK=34

AftabUfaq commented 8 months ago

I also ugpraded to API Level 34 and applied the patch from above. But now, after about 160 seconds of having the app in the bg, I get this message. Did any of you face that?

image

did you solved it

nop33 commented 8 months ago

Yes. I replaced shortService with dataSync. I also had to this to my expo config:

expo: {
    android: {
      permissions: [
        'android.permission.FOREGROUND_SERVICE_DATA_SYNC',
      ]
    }
}

This was my patch (generated by pnpm patch)

diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
index b67ef4d1837363489a1749acb852997a6c93c1b5..6aa30a826c2f17a35ccd30b64291d3d20006e864 100644
--- a/android/src/main/AndroidManifest.xml
+++ b/android/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions">
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <application>
-        <service android:name=".RNBackgroundActionsTask"/>
+        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync" />
     </application>
 </manifest>
diff --git a/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java b/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
index 315dbd4c10155c54302fa04e3bef5067d78003cb..9900fc0654f1cfd75acd77b46734ea144c3dcb40 100644
--- a/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
+++ b/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
@@ -41,7 +41,9 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
             notificationIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
         }
         final PendingIntent contentIntent;
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+        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);
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
devtyty commented 8 months ago
FOREGROUND_SERVICE_DATA_SYNC

I think you should set service type in your own's app. Don't modify on the lib

nop33 commented 8 months ago

That's why I said "to my expo config". This is my own app's config file. But this is still needed to be patched:

android:foregroundServiceType="dataSync"
AftabUfaq commented 8 months ago

That's why I said "to my expo config". This is my own app's config file. But this is still needed to be patched:

android:foregroundServiceType="dataSync"

should I add this to android minifies file or in the patch file of AndroidManifest.xml of the project

nop33 commented 8 months ago

Sorry, the diff that I showed comes from pnpm patch, it refers to the files of the react-native-background-actions package.

should I add this to android minifies file or in the patch file of AndroidManifest.xml of the project

I added this to this file:

node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
pratikSeven commented 7 months ago

Currently I have downgraded SDK version from 34 to 33. It is working fine but I dont think this the best idea to do. Is there any fix for this issue ?

nop33 commented 7 months ago

What I described worked for me.

mostasim commented 7 months ago

Yes. I replaced shortService with dataSync. I also had to this to my expo config:

expo: {
    android: {
      permissions: [
        'android.permission.FOREGROUND_SERVICE_DATA_SYNC',
      ]
    }
}

This was my patch (generated by pnpm patch)

diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
index b67ef4d1837363489a1749acb852997a6c93c1b5..6aa30a826c2f17a35ccd30b64291d3d20006e864 100644
--- a/android/src/main/AndroidManifest.xml
+++ b/android/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions">
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <application>
-        <service android:name=".RNBackgroundActionsTask"/>
+        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync" />
     </application>
 </manifest>
diff --git a/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java b/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
index 315dbd4c10155c54302fa04e3bef5067d78003cb..9900fc0654f1cfd75acd77b46734ea144c3dcb40 100644
--- a/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
+++ b/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java
@@ -41,7 +41,9 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
             notificationIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
         }
         final PendingIntent contentIntent;
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+        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);
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

this works for me

gokul-sirpi commented 7 months ago

@ng-ha you can use this patch for android 14

index b67ef4d..cf8cab4 100644
--- a/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
+++ b/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions">
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <application>
-        <service android:name=".RNBackgroundActionsTask"/>
+        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="shortService"/>
     </application>
 </manifest>
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 315dbd4..ccba9a6 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
@@ -40,8 +40,11 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
             //as RN works on single activity architecture - we don't need to find current activity on behalf of react context
             notificationIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
         }
+
         final PendingIntent contentIntent;
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+        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);
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

applied this above patch, the app runs for 3mins and then the app stops and quit by itself even if i was inside the app. Can anyone help me with this? Also i didn't get any error logs for this issue

nop33 commented 7 months ago

Read the docs for shortService, that's why you get 3 minutes. See my reply where I use dataSync.

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 4.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Yashi1919 commented 2 months ago

My app is still crashing on android 14 when i start my background service

this is my manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.wallodynamo">

<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<!-- Foreground Service Permissions -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" tools:targetApi="m" />

<!-- Location Permissions -->
<!-- ACCESS_FINE_LOCATION allows fine (GPS) location access -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- ACCESS_BACKGROUND_LOCATION should be requested only if your app truly requires background location access -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
    tools:targetApi="r" />

<!-- Storage Permissions - Use Scoped Storage instead of broad permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:targetApi="30"/>

<application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/wallo"
    android:roundIcon="@mipmap/wallo"
    android:allowBackup="false"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

    <!-- Main Activity -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter android:label="filter_react_native">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="wallodynamo" />
        </intent-filter>
    </activity>

    <!-- Foreground Service Declaration -->
    <service
        android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"
        android:exported="false"
        android:foregroundServiceType="location|mediaPlayback|dataSync"
        android:permission="android.permission.BIND_JOB_SERVICE"
        tools:replace="android:foregroundServiceType">
    </service>

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

priyanshubuddy commented 2 months ago

My app is still crashing on android 14 when i start my background service

this is my manifest file

<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<!-- Foreground Service Permissions -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" tools:targetApi="m" />

<!-- Location Permissions -->
<!-- ACCESS_FINE_LOCATION allows fine (GPS) location access -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- ACCESS_BACKGROUND_LOCATION should be requested only if your app truly requires background location access -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
    tools:targetApi="r" />

<!-- Storage Permissions - Use Scoped Storage instead of broad permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:targetApi="30"/>

<application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/wallo"
    android:roundIcon="@mipmap/wallo"
    android:allowBackup="false"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

    <!-- Main Activity -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter android:label="filter_react_native">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="wallodynamo" />
        </intent-filter>
    </activity>

    <!-- Foreground Service Declaration -->
    <service
        android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"
        android:exported="false"
        android:foregroundServiceType="location|mediaPlayback|dataSync"
        android:permission="android.permission.BIND_JOB_SERVICE"
        tools:replace="android:foregroundServiceType">
    </service>

found any solution ?

vishalyad16 commented 1 month ago

Not able to release app playstore blocking the release requesting for a video with foreground service, please help with solution! BTW why do we need FOREGROUND_SERVICE_DATA_SYNC?? @nop33 @DZamataev @caleblawrence @mostasim @AftabUfaq ?

mostasim commented 1 month ago

Not able to release app playstore blocking the release requesting for a video with foreground service, please help with solution! BTW why do we need FOREGROUND_SERVICE_DATA_SYNC?? @nop33 @DZamataev @caleblawrence @mostasim @AftabUfaq ?

@vishalyad16 Yes we need to add the permission FOREGROUND_SERVICE_DATA_SYNC

Devendra7409 commented 3 days ago

@ng-ha you can use this patch for android 14

index b67ef4d..cf8cab4 100644
--- a/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
+++ b/node_modules/react-native-background-actions/android/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions">
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
     <application>
-        <service android:name=".RNBackgroundActionsTask"/>
+        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="shortService"/>
     </application>
 </manifest>
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 315dbd4..ccba9a6 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
@@ -40,8 +40,11 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
             //as RN works on single activity architecture - we don't need to find current activity on behalf of react context
             notificationIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
         }
+
         final PendingIntent contentIntent;
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+        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);
+        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);

in which file in react native ?