Missing PendingIntent
mutability flag ---> this is the warning in my android kotlin project. I am using headsup notification in it. In this, while setting pending intent, if i set 0 to pending intent content [val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)] , Missing "PendingIntent
mutability flag" warning arised.
If i use pending intent. FLAG_IMMUTABLE, my project getting error after i have released my app bundle in google play console. error--- [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]. What should i use in the notifications. I am using API level 26. Can anyone help me please.
private fun createNotification(title: String, description: String) {
val s = "Messages"
val intent = Intent(this, MainActivity::class.java)
intent.putExtra("fragmsg", s)
Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
val pendingIntent =
PendingIntent.getActivity(this, 0, intent, 0)
val notificationManager =
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel =
NotificationChannel("101", "channel", NotificationManager.IMPORTANCE_HIGH)
notificationManager.createNotificationChannel(notificationChannel)
notificationChannel.lightColor = Color.BLUE
notificationChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
// notificationChannel.enableVibration(true)
}
val notificationBuilder =NotificationCompat.Builder(applicationContext, "101")
.setContentTitle(title)
.setContentText(description)
.setSmallIcon(R.drawable.logof)
.setPriority(PRIORITY_HIGH)
.setAutoCancel(true)
.setOngoing(false)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
notificationManager.notify(1, notificationBuilder.build())
}