Skip to content

Instantly share code, notes, and snippets.

@navczydev
Last active October 22, 2021 02:02
Show Gist options
  • Save navczydev/5210681ad12d49ccd47ce4f04d6d66f0 to your computer and use it in GitHub Desktop.
Save navczydev/5210681ad12d49ccd47ce4f04d6d66f0 to your computer and use it in GitHub Desktop.
val broadcastIntent = Intent(context.applicationContext, NotificationReceiver::class.java)
val actionIntent = PendingIntent.getBroadcast(
context.applicationContext,
0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT or
// mutability flag required when targeting Android12 or higher
PendingIntent.FLAG_IMMUTABLE
)
// notification code
val notification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Android12")
.setContentText("Notification trampoline restrictions")
.addAction(R.mipmap.ic_launcher, "Open activity from receiver", actionIntent)
.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