Skip to content

Instantly share code, notes, and snippets.

@navczydev
Created October 22, 2021 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navczydev/017ead471a49d3fe3c977f4f62cac40b to your computer and use it in GitHub Desktop.
Save navczydev/017ead471a49d3fe3c977f4f62cac40b to your computer and use it in GitHub Desktop.
val notificationTrampolineActivityIntent =
Intent(context.applicationContext, NotificationTrampolineActivity::class.java)
// Create the TaskStackBuilder
val resultPendingIntent: PendingIntent? = TaskStackBuilder.create(context).run {
// Add the intent, which inflates the back stack
addNextIntentWithParentStack(notificationTrampolineActivityIntent)
// Get the PendingIntent containing the entire back stack
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or
// mutability flag required when targeting Android12 or higher
PendingIntent.FLAG_IMMUTABLE)
val notification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Android12")
.setContentText("Notification trampoline restrictions fix")
.addAction(R.mipmap.ic_launcher, "Open activity", resultPendingIntent)
.setAutoCancel(true)
.build()
notificationManager.notify(getUniqueId(), notification)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment