Issue
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?
Solution
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.
Answered By - Zain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.