The app crash when using targetSdkVersion greater than 33
When set targetSdkVersion = 34 or targetSdkVersion = 35, when do .start() the app crashes
Downgrade to targetSdkVersion = 33, and the App is OK
yes in my side also app is crash after BackgroundService.updateNotification did you get any solution
Hi, you can follow these steps for versions higher than >= 34.
- Go to android manifest and add these lines:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" /> // or special use may be here check this link: https://developer.android.com/about/versions/14/changes/fgs-types-required
and add these line between <activity></activty> tags.
<service
android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"
android:foregroundServiceType="location" //https://developer.android.com/about/versions/14/changes/fgs-types-required
android:exported="false">
</service>
and go to this path: /node_modules/react-native-background-actions/android/src/main/java/com/asterinet/react/bgactions/RNBackgroundActionsTask.java and replace onStart function:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final Bundle extras = intent.getExtras();
if (extras == null) {
throw new IllegalArgumentException("Extras cannot be null");
}
final BackgroundTaskOptions bgOptions = new BackgroundTaskOptions(extras);
createNotificationChannel(bgOptions.getTaskTitle(), bgOptions.getTaskDesc()); // Necessary creating channel for API 26+
// Create the notification
final Notification notification = buildNotification(this, bgOptions);
if (Build.VERSION.SDK_INT >= 34) {
startForeground(SERVICE_NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); // //https://developer.android.com/about/versions/14/changes/fgs-types-required
}else {
startForeground(SERVICE_NOTIFICATION_ID, notification);
}
return super.onStartCommand(intent, flags, startId);
}
Also check this link please: https://stackoverflow.com/questions/77520968/why-am-i-encountering-the-error-starting-fgs-without-a-type-when-executing-the
crashing on app launch when targetSDK updated to 35 as per play console requirements
Try this
Starting FGS with type connectedDevice require
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
Patch file: react-native-background-actions+4.0.1.patch