Created
October 22, 2021 01:52
-
-
Save navczydev/017ead471a49d3fe3c977f4f62cac40b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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