Scenario: I have a Cordova based android app which targets android SDK = 31.It uses a location tracking plugin. It runs perfectly on android 11 and lower mobiles. In case of android 13, it only crashes in scenarios when the location tracking starts.
Here's the Bug report generated by android 13 mobile:
java.lang.RuntimeException: Unable to start service com.marianhello.bgloc.LocationService@705152b with Intent { flg=0x4 cmp=com. myapp.com/com.marianhello.bgloc.LocationService (has extras) }: java.lang.IllegalArgumentException: com. myapp.com: 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.ActivityThread.handleServiceArgs(ActivityThread.java:4846)
at android.app.ActivityThread.access$2200(ActivityThread.java:275)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2223)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:211)
at android.os.Looper.loop(Looper.java:300)
at android.app.ActivityThread.main(ActivityThread.java:8301)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:577)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.IllegalArgumentException: com. myapp.com: 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 com.marianhello.bgloc.ActivityRecognitionLocationProvider.onCreate(ActivityRecognitionLocationProvider.java:60)
at com.marianhello.bgloc.LocationProviderFactory.getInstance(LocationProviderFactory.java:43)
at com.marianhello.bgloc.LocationService.onStartCommand(LocationService.java:239)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4828)
... 9 more
I have tried different solutions available on this platform as well as on others too.
I'm facing similar issue like this user: Targeting 31+ SDK requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent? but the answers on the above question didn't work for me:(