mhmdnasser124 / react-native-background-runner

MIT License
11 stars 0 forks source link

App crash when Service.startRunnerTask called in android 13 and above #2

Open pdeep29 opened 8 months ago

pdeep29 commented 8 months ago

When i start Service.startRunnerTask it works fine in android 12 or bellow but in android 13 and above app gets crashed in android device.

phtepic commented 7 months ago

On Android 13 and 14 works well. Since Android 14 you have to add new permission and define service into Manifest.xml file for foreground service type. Code example below. Add permission:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" android:minSdkVersion="34" />

and service:

<service android:name="com.backgroundrunner.BackgroundRunnerTask" android:exported="true" android:foregroundServiceType="location"/>
pdeep29 commented 7 months ago

since i have been facing this issue in react-native background actions i have found a solution with this changes

react-native-background-actions package android folder androidmanifest.xml replace - with -

react-native background actions RNBackgroundActionsTask.java file changes replace -
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { with - 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) {

project android manifext.xml all following changes

 <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="MarketingApp" /> 
  </intent-filter>
  </activity>
  <!-- <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
  <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" /> -->
       <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="dataSync" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
pdeep29 commented 7 months ago

since i found the solutions given above closing the issue