'App crash when It makes API call using Retrofit on Android 12 API 32
Can anybody help me please. I already have added FLAG_IMMUTABLE
flag to all pending intents for supporting Android 12, but when try to call any API using retrofit on app start, app thorws below exception and crash.
Http Log
I/okhttp.OkHttpClient: --> GET https://api.covantex.com/v1/EnvironmentFlags
I/okhttp.OkHttpClient: --> END GET
I/okhttp.OkHttpClient: <-- HTTP FAILED: java.lang.IllegalArgumentException: com.covantex: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
I/okhttp.OkHttpClient: 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.
I/okhttp.OkHttpClient: <-- HTTP FAILED: java.lang.IllegalArgumentException: com.covantex: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
I/okhttp.OkHttpClient: 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.
Libraries for using APIs
implementation "com.google.code.gson:gson:2.9.0"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.2"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation "com.squareup.retrofit2:converter-scalars:2.9.0"
Solution 1:[1]
Try like this: PendingIntent clickPendingIntent = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Matt |