Android API 31+ requires mutability flag for PendingIntent; ServerPingWithAlarmManager 4.4.5 fails

Android API version 31 (Android S) and above require any PendingIntent to have one of two flags set: FLAG_IMMUTABLE or FLAG_MUTABLE. (Android doc.) ServerPingWithAlarmManager.onCreate doesn’t do this, and so is throwing an IllegalArgumentException.

(ServerPingWithAlarmManager uses the flag 0 when creating a PendingIntent to pass to AlarmManager.)

java.lang.IllegalArgumentException: com.<app package name>: 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:375)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
        at org.jivesoftware.smackx.ping.android.ServerPingWithAlarmManager.onCreate(ServerPingWithAlarmManager.java:166)

In order for ServerPingWithAlarmManager to work on apps targeting Android S and above, it’ll need to be updated to use one of those flags instead of 0.

Thanks for reporting. For now, if you want to use Smack with an Android app that targets API level 31, you may need to disable ServerPingWithAlarmManager and potentially create your own instance of the manager where the pending intent is created with the appropriate flag.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.