Slide 39
Slide 39 text
Trampoline
notification
// Let’s build the notification with the Broadcast
val broadcastIntent = Intent(context,
NotificationReceiver::class.java)
val actionIntent = PendingIntent.getBroadcast(
context,
0,
broadcastIntent,
PendingIntent.FLAG_UPDATE_CURRENT or
PendingIntent.FLAG_IMMUTABLE
)
val notification = NotificationCompat.Builder(context,
CHANNEL_ID)
.setSmallIcon(R.drawable.icon)
.setContentTitle("Android12")
.setContentText("Notification trampoline")
.addAction(R.drawable.icon, "Open activity",
actionIntent)
.build()
notificationManager.notify(getUniqueId(), notification)
Indirect notification activity start (trampoline) from
PACKAGE_NAME, this should be avoided for performance
reasons.
●
Android 12 restricts the trampoline
effect with notifications
●
It’s now forbidden to open an
Activity from a Service or a
BroadcastReceiver