Reputation: 33
For me, when using the method (chain.proceed (request)), there is a problem which is the following error.
My error happens in Android 12
I use retrofit
class CustomInterceptor implements Interceptor {
@NonNull
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request ();
return chain.proceed (request);
}
}
Exception
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.
Upvotes: 2
Views: 1516
Reputation: 63
I had the same problem today. The root problem was not okHttp / Retrofit, but Gander, a Http inspection library that I use in my app. The library is not maintained anymore, which means they do not support Android 12. I guess I'll have to switch to Chucker or some other alternative.
If you would provide the full stacktrace we could see, which library is really causing your problem. Removing or updating that library might help you.
See also the issue in the OkHttp GitHub repo: https://github.com/square/okhttp/issues/7034. The developers of OkHttp / Retrofit ensure in their response, that the two libraries are not the problem.
Upvotes: 2
Reputation: 5205
This is the way how to handle updatingPendingIntent according to the error that you sent. I don't think the code and the error you mentioned is related.
val updatedPendingIntent = PendingIntent.getActivity(
applicationContext,
NOTIFICATION_REQUEST_CODE,
updatedIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT // setting the mutability flag
)
Android Developers- Pending Intent Mutability
chain.proceed (request)
is a form of Chain of Responsibility principle each interceptor is a processing object which acquires the result of the previous interceptor through chain.request() applies its own logic on it (by a builder pattern), and usually pass it to the next unit (interceptor) using chain.proceed.
Stack Overflow Answer on Changes Required for Targeting S+ and solving the error
Upvotes: 0