Hey I am getting warning for pending intent. So I surrounded for check of checking sdk according to this question and this medium post. I am getting warning message
Missing PendingIntent mutability flag
val pendingIntent: PendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} else {
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}

How can I remove this warning message?

Your code seems OK, and I believe it's a bug in the Lint check as it's been
stated by @CommonsWare in comments. This could be fixed in the next releases of Android Studio
How can I remove this warning message?
If you just want to remove the annoying warning there is a hack in building the condition that clear the warning: by transferring the conditional to the flag:
val pendingIntent: PendingIntent = PendingIntent.getActivity(
this,
0,
intent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
else PendingIntent.FLAG_UPDATE_CURRENT
)
Or at the worse case you'd suppress it by @SuppressLint("UnspecifiedImmutableFlag"), which I don't recommend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With