Android Notification buttons not showing up
Asked Answered
R

9

44

This is my code to set up a notification with buttons.

Intent receiverIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        PendingIntent pReceiverIntent = PendingIntent.getActivity(ctx, 1, receiverIntent, 0);
        Intent clearIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        clearIntent.setAction("clear");
        PendingIntent pClearIntent = PendingIntent.getActivity(ctx, 1, clearIntent, 0);

        Intent colorsIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        colorsIntent.setAction("colors");
        PendingIntent pColorsIntent = PendingIntent.getActivity(ctx, 1, colorsIntent, 0);

        Intent animationIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        animationIntent.setAction("animation");
        PendingIntent pAnimation = PendingIntent.getActivity(ctx, 1, animationIntent, 0);

        Notification.Builder builder;
        builder = new Notification.Builder(ctx).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false)
                .setContentTitle("Draw Me: A Live Wallpaper").setContentText("Never get bored again!")
                .setContentIntent(pReceiverIntent).addAction(R.raw.ic_menu_close_clear_cancel, "Clear", pClearIntent)
                .addAction(R.raw.ic_menu_edit, "Colors", pColorsIntent).addAction(R.raw.ic_menu_play_clip, "Animation", pAnimation);
        Notification notification = builder.build();

        NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notification);

Notification is showing up but buttons don't. My device has Android 4.1.1 I set up this notification in a Fragment. What am I doing wrong? Thanks!

Roots answered 15/8, 2013 at 9:28 Comment(0)
D
133

Let me tell you something which is really awkward. If you have anything in your Ongoing Notification, You wont see the buttons. Typically it happens when you have phone connected to PC via USB. Hope this solves your problem

Daughterly answered 28/8, 2013 at 0:38 Comment(8)
The answer of the year....I blamed the last OS update I've made (4.2.2) but isn't its direct fault....Deron
great answer. I also got around this using @Captain Blammo answer by calling .setPriority(Notification.PRIORITY_MAX) on my noticiation builder. This way you can still see the buttons even while you're connected via USBPhellem
You can always swipe downwards on your notification to expand it and show the buttons even when there are other notifications around it. :)Avila
If you have ANYTHING IN YOUR NOTIFICATION? what does that even mean?Jerrylee
"ANYTHING IN YOUR NOTIFICATION" means any other notfication i.e anything :-)Daughterly
oh, I see, you're right!, Thanks, sorry if I sounded a bit harshJerrylee
I'm not entirely sure why this is the accepted answer and has tons of upvotes. It's easily fixed! I've put an answer down below that works. It only has 9 upvotes, and isn't accepted despite actually working.Silda
It works, thanks. But it is weird that the notification action button will not show when in landscape orientation even the USB is not connected.Postoperative
G
31

Just a reminder for anyone with a similar issue. As per the Android Notifications Guide, notifications can appear in two styles:

  • Normal View, where the action buttons don't appear by default (and the user has to expand the notification, in order for them to appear)
  • Big View, which is visible if the notification is first in the notification list, or the user has expanded the notification.

Therefore in order to force the notification to appear in Big View, all we have to do is simply place it on the top of the Notifications list. That can be done by setting the When property to 0 which makes it the oldest among notifications! (Sometimes though we may not want this). So call

setWhen(0)

to your notification and you're done.

Guelph answered 3/9, 2013 at 23:30 Comment(3)
Or even better set the notification's priority to MAX! setPriority(Notification.PRIORITY_MAX)Guelph
You should have added that as an answer! May the good Lord bless you!Dissemblance
I ended up having to put both setWhen(0) and setPriority(MAX) to have this work on android 4.4Zoltai
S
26

The buttons won't appear when there is any Ongoing Notification present in the list, such as a media player control, or the IME switcher options when you are editing text.

Luckily, this can be overcome simply by setting the priority of the notification nice and high. I've only ever used Notification.PRIORITY_MAX to get around this, but PRIORITY_HIGH seems to work as well. Set it like this:

Notification notification = new Notification.Builder(myContext)
.setContentTitle(res.getString(R.string.my_title))
.setPriority(Notification.PRIORITY_MAX)
//The rest of your options
.build();
Silda answered 17/12, 2013 at 0:16 Comment(3)
Priority setting is now depricated. Is there a newer solution?Highjack
Any new solutions? cause its deprecatedToomay
We can use setPriority(NotificationCompat.PRIORITY_HIGH) instead of setPriority(Notification.PRIORITY_MAX).Smoulder
F
18

Just Do this :::

.setPriority(Notification.PRIORITY_MAX)
.setWhen(0)

full code is :

Notification noti = new Notification.Builder(this)
            .setContentTitle("New mail from " + "[email protected]")
            .setContentText("Subject").setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(pIntent)
            .setPriority(Notification.PRIORITY_MAX)
            .setWhen(0)
            .addAction(R.drawable.ic_launcher, "Call", pIntent)
            .addAction(R.drawable.ic_launcher, "More", pIntent)
            .addAction(R.drawable.ic_launcher, "And more", pIntent).build();
Feltie answered 9/9, 2014 at 13:3 Comment(0)
S
1

If you wonder why the "buttons" do not show up with the assigned icons (only the text gets displayed - not even as a button, no visible border - material design says so i guess) its probably because android decided to ditch showing the icons, while not documenting this deprecation anywhere in the addAction-Method.

At least none of the accepted answers above (back from 7 years ago) made any icons appear for me on sdk-28 (android 10) - so i figure it must be a undocumented design decision until proven otherwise :)

Shrinkage answered 11/12, 2019 at 0:1 Comment(0)
F
0

In my case, the action buttons didn't show up because I was using a custom view for the notification content with the RemoteViews()

Fie answered 22/4, 2018 at 23:9 Comment(0)
E
0

In my case it was a persistent notification that I have added. Meaning actions won't show if you have a persistent notification showing.

Edwyna answered 17/10, 2021 at 21:44 Comment(0)
S
0

I faced this issue in NotificationCompat.Builder, I have done below points,

added below lines:

.setPriority(NotificationCompat.PRIORITY_HIGH)

.setWhen(0)

removed below line:

.setContentIntent(pendingIntent)

After these changes the buttons were shown in the Notifications.

Smoulder answered 29/3, 2023 at 9:9 Comment(0)
B
-1

Just do some changes like this in your code

Notification n = new Notification.Builder(this)
                .setSmallIcon(R.drawable.icon)
                .setContentTitle("New mail from " + "[email protected]")
                .setContentText("Subject")
                .setContentIntent(pIntent).setAutoCancel(true)
                .setStyle(new Notification.BigTextStyle().bigText(longText))
                .build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        // Hide the notification after its selected

        notificationManager.notify(0, n);

Add what you need in this.. I hope it will helps you..

Barm answered 15/8, 2013 at 14:52 Comment(2)
I already have that as it can be seen. I don't need the setStyle method because I want small buttons. What I learned though is that buttons were not showing when tablet was connected to pc through USB. When I disconected the tablet the buttons showed up. This has been happening on E-BODA Impresspeed E200 and Samsung Galaxy Note Tab 10.1 both with JB. This is just crazy, half a day wasted! Anyone else got this problem?Roots
It's a bug in pretty much all Samsung Android devices. So, you're not the only one facing this issue. As usual, Samsung breaks Android functionality with its TouchWiz crap!...Hopple

© 2022 - 2025 — McMap. All rights reserved.