2

My app uses Parse SDK for Android and GCM to get notification after a change on Parse database.

The app's onCreate() calls the line:

ParseGCM.register(context);

On Android 13 device, this line causes a RuntimeException exception:

Caused by: java.lang.IllegalArgumentException: com.myapp: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. at android.app.PendingIntent.checkFlags(PendingIntent.java:401) at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671) at android.app.PendingIntent.getBroadcast(PendingIntent.java:658) at com.firebase.jobdispatcher.GooglePlayDriver.(GooglePlayDriver.java:72) at com.parse.gcm.ParseGCM.register(ParseGCM.java:39)

The crash does not occur on Android 11

matdev
  • 4,115
  • 6
  • 35
  • 56
  • Update to the latest Parse SDK. If you're on the latest, since Parse was discontinued, you may be out of luck. I forget if that SDK is open source or not -- if it is, you might need to fork it and modify it to fix their bug. – CommonsWare Feb 02 '23 at 15:25
  • I've tried updating the Parse SDK to latest version 4.5.0, but the app no longer builds (it's a legacy app). A fork may be the solution, thanks – matdev Feb 02 '23 at 15:34

1 Answers1

3

Worth checking if your code is dealing with pending intents, because for API level 31 and beyond, you will have to specify the mutability of each PendingIntent object that your app creates. Please just keep in mind things like https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE are as of SDK 23 - hope that's not an issue.

So if your code was like this:

PendingIntent pendingIntent = PendingIntent.getActivity(context, <your request code>, 
    intent, 
    PendingIntent.FLAG_UPDATE_CURRENT
);

you will have to change it to something like this:

PendingIntent pendingIntent = PendingIntent.getActivity(context, <your request code>,
    intent,
    PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT
);
ror
  • 3,295
  • 1
  • 19
  • 27
  • The exception occurs in a dependency that I cannot upgrade for legacy compatibility. I cannot apply your solution, but I accept it, as it would work on custom code. – matdev Feb 15 '23 at 11:31