val pendingIntent = PendingIntent.getBroadcast(context, 0, intent,…
- User
val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
java.lang.RuntimeException: Unable to create service com.xegera.trucking.UpdateLocationService: java.lang.IllegalArgumentException: com.xegera.trucking: 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.
- Assistant
The error message indicates that you are targeting Android S (API level 31) or above, which enforces the use of either FLAG_IMMUTABLE or FLAG_MUTABLE when creating a PendingIntent. To fix this issue, you can modify your PendingIntent creation by adding one of these flags.
If the PendingIntent does not need to change after being created, use FLAG_IMMUTABLE:
javaval pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);If the PendingIntent needs to be mutable, e.g., because it is used with inline replies or bubbles, use FLAG_MUTABLE:
javaval pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);Keep in mind that mutable PendingIntents are less secure and are more prone to potential vulnerabilities, so it's strongly recommended to use FLAG_IMMUTABLE unless the functionality requires a mutable PendingIntent.