I am adding two buttons to a notification in my app that is set to target API Level 8. The problem is that the two buttons appears as two large grey buttons, totally out of place with the rest of the notifications. I've tested it both on Nexus 7 and Galaxy Nexus.
All examples I've seen have the nice looking black buttons like the incoming call notification: http://www.androidng.com/wp-content/uploads/2012/07/android-jelly-bean-notifications.jpeg
I would guess this would be easy, but no such luck today. Does anyone know where I might have taken the wrong turn? Below is a snippet of my code which generates the notification with the latest support library.
NotificationManager nm = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(this);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_radio)
.setContentTitle(message)
.setTicker(message)
.setPriority(android.support.v4.app.NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setAutoCancel(false)
.addAction(android.R.drawable.ic_btn_speak_now, "Play", contentIntent)
.addAction(android.R.drawable.ic_dialog_map, "Stop", contentIntent)
.setContentText(message);
Notification n = builder.build();
//nm.notify(0, n);
startForeground(1, n);
Adding an action button: It is similar to setting the tap action by creating a pending intent only change is that we set it using addAction() to attach it to the notification. We can create intents for both activities or broadcast receivers as shown below: You can create your own BroadcastReciever.
What Are Push Notification Action Buttons? This is a case where the name is actually pretty self-explanatory: Push notification action buttons are literal buttons that can be added to the push notifications you send in order to allow recipients to take action on the messages they receive.
A notification is a message that Android displays outside your app's UI to provide the user with reminders, communication from other people, or other timely information from your app. Users can tap the notification to open your app or take an action directly from the notification.
App icon badges tell you when you have unread notifications. An app icon badge shows you the number of unread alerts and it's omnipresent on the app icon.
So this is happening because your targetSdk in your AndroidManifest.xml is < 11.
I believe the change in compatibility that happens when you target 11 is that the default theme because Holo. Since yours (and my) target is less than 11, it's resorting to some compatibility theme that it applies on these buttons even though it shouldn't. I assume that even though your app / activity is set to Holo, it doesn't actually apply to the notification since they are are in a different process.
That's just my guess. Using CommonsWare's notification demo and just modify the targetSdk shows this behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With