1

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())

}
Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
chanthini begam
  • 109
  • 1
  • 11
  • Maybe this link could help you: https://stackoverflow.com/questions/67045607/how-to-resolve-missing-pendingintent-mutability-flag-lint-warning-in-android-a If you use firebase, try update it. – Felipe Palma Dec 29 '22 at 12:50

1 Answers1

1
val pendingIntent =
        PendingIntent.getActivity(
   this,
   0,
   intent,
   PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT // setting the mutability flag 
)

According to the docs here: https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability

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.

Choose your flag accordingly.

If you want to read more about this i would suggest that you read this great article here: https://medium.com/androiddevelopers/all-about-pendingintents-748c8eb8619

sajidjuneja
  • 184
  • 7