Blog Infos
Author
Published
Topics
,
Author
Published
Did you ever notice?

What is a Notification trampoline?
Android12 restrictions
Error message in logcat
Indirect notification activity start (trampoline) from PACKAGE_NAME, \
this should be avoided for performance reasons.
Sample code that will create this issue
class NotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// from Android12 this will not work
// Indirect notification activity start (trampoline) from PACKAGE_NAME, \ this should be
//avoided for performance reasons.
context.startActivity(Intent(context, NotificationTrampolineActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
})
}
}

NotificationReceiver.kt

 

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)

NotificationWithReceiverIntent.kt

 

Identify which app components act as notification trampolines
adb shell dumpsys activity service \ com.android.systemui/.dump.SystemUIAuxiliaryDumpService
A section of the output includes the text "NotifInteractionLog".
This section contains the information that's necessary to identify the component that starts as the result of a notification tap.

Job Offers

Job Offers


    Android Build Engineer

    Pinterest
    San Francisco, CA | Seattle, WA
    • Full Time
    apply now

    Senior Mobile Systems SDK Engineer

    Sauce Labs
    Remote
    • Full Time
    apply now

    Android App Developer

    sipgate GmbH
    Düsseldorf, Remote
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

,

Leveling Up Your Tests

We all know about TDD and Unit Testing, and even screenshot testing, but sometimes we do not need to embrace a new paradigm to make our tests better. These are several techniques I have adopted…
Watch Video

Leveling Up Your Tests

Jobs

Toggle the behavior

App compatibility flag

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)

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
It’s one of the common UX across apps to provide swipe to dismiss so…
READ MORE
blog
In this part of our series on introducing Jetpack Compose into an existing project,…
READ MORE
blog
Nowadays authentication has become common in almost all apps. And many of us know…
READ MORE
blog
Collections are a set of interfaces and classes that implement highly optimised data structures.…
READ MORE

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu