react-native-background-actions
react-native-background-actions copied to clipboard
Android 14+ Crash: PendingIntent with `FLAG_MUTABLE` causes app to crash on SDK 34+
Description:
When targeting Android 14 (SDK 34+), the app crashes due to usage of a PendingIntent with FLAG_MUTABLE and an implicit intent in RNBackgroundActionsTask.java. This behavior is restricted by the OS for security reasons.
To Reproduce:
Set compileSdkVersion = 34 and targetSdkVersion = 34 Use react-native-background-actions to run a background task
Observe crash logs:
java.lang.IllegalArgumentException: Targeting U+ disallows creating or retrieving a PendingIntent with FLAG_MUTABLE and an implicit Intent...
Problematic Code (Current Implementation):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
}
Proposed Fix:
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
if (intent != null) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
}
+1
+1
+1
@khaledbk Still App is crashing . Can you please provide full code ?