react-native-background-actions icon indicating copy to clipboard operation
react-native-background-actions copied to clipboard

Android 14+ Crash: PendingIntent with `FLAG_MUTABLE` causes app to crash on SDK 34+

Open khaledbk opened this issue 5 months ago • 4 comments

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);
}

khaledbk avatar Jul 22 '25 22:07 khaledbk

+1

ap9086013 avatar Jul 28 '25 05:07 ap9086013

+1

Thilanka-97 avatar Aug 15 '25 15:08 Thilanka-97

+1

Raed-sh avatar Sep 18 '25 20:09 Raed-sh

@khaledbk Still App is crashing . Can you please provide full code ?

SurajMohanty02 avatar Oct 24 '25 06:10 SurajMohanty02