I am creating notification with button:
val builder = NotificationCompat.Builder(MyApp.appContext, FCM_CHANNEL)
.setSmallIcon(R.drawable.noticon)
.setLargeIcon(image)
.setContentTitle(user?.name)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
And adding pendingIntent:
val responseIntent = Intent(MyApp.appContext, ResponseBroadcastReceiver::class.java)
responseIntent.putExtra(ResponseBroadcastReceiver.USER_ID, fromUid)
val flags: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_ONE_SHOT
else
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_ONE_SHOT
val pendingIntent = PendingIntent.getBroadcast(MyApp.appContext, abs(fromUid.hashCode()), responseIntent, flags)
builder.addAction(0, "Reply", pendingIntent)
builder.setContentText("Please respond")
I have couple of questions:
- Because for each notification I create new pendingIntent how can I list all of them to see which active? As I understand I am limited to 35 (what happens after 35?) https://stackoverflow.com/a/20205696
- Does adding "setAutoCancel(true)" to NotificationCompat.Builder removes the pendingIntent when notification dismissed (that is what I want)
- I wish that bending intent only be triggered once (PendingIntent.FLAG_ONE_SHOT) and Mutable, is this the correct approach for handling different SDK versions?