RxJava or Retrofit PendingIntent error with Android 12 (S)

613 Views Asked by At

I'm trying to change targeting version to Android 12 (S). But I have an error

java.lang.IllegalArgumentException: : 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.

The code, that producing this error is:

return regRestClient.getToken(idRef)
            .onErrorResumeNext(
                    regRestClient.registerDevice(idRef, Build.PRODUCT, Build.MODEL)
                    .flatMap(response -> regRestClient.getToken(idRef))
            )
            .map((result) ->
                    new TokenResult(result.getToken())
            )
            .doOnError(error -> provideActivityToConsumer(activity -> onRegFailed(activity, error)))
            .onErrorReturn(throwable -> new TokenResult(null));

Get device token query:

@GET("device/{deviceId}")
@Headers( {Api.HEADER, Api.AUTH})
Single<TokenResult> getToken(@Path("idd") IdRef id);

I don't understand, it seems that RxJava libraries or retrofit libraries have some PendingIntent functionality, but I don't understand which exactly library.

my libraries:

 implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
 implementation 'io.reactivex.rxjava2:rxjava:2.2.18'
 implementation 'com.squareup.retrofit2:retrofit:2.9.0'
 implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
 implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'

Please help!

2

There are 2 best solutions below

0
On

Just add this dependency to your app module and everything will be good by some reason.

implementation 'androidx.work:work-runtime-ktx:2.7.1'

There is source of information: https://developer.android.com/jetpack/androidx/releases/work#version_27_2

0
On

In my case, I used library - 'com.readystatesoftware.chuck:library:..*'. And this library contains itself notification and its notification is not working for Android 12 (S).

If you also used this library for debugging, just remove it and try again.