Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotificationBuilder or NotificationCompat.Builder does not show actions

Tags:

android

Playing with this for three hours and can't figure what's wrong.

private static Notification buildNotification(Context context) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(context);
    b.setContentIntent(PendingIntent.getActivity(
            context, 0, new Intent(context,  MyActivity.class),
                PendingIntent.FLAG_UPDATE_CURRENT));
    b.setTicker(context.getString(R.string.update_notification_title));
    b.setContentTitle(context.getString(R.string.update_notification_title));
    b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon));
    b.setSmallIcon(R.drawable.icon);
    b.setOngoing(true);
    b.setAutoCancel(false);
    b.setProgress(100, 0, true);

    Intent cancel = new Intent(context,  Updater.class);
    cancel.putExtra(EXTRA_CANCEL, true);
    b.addAction(
            R.drawable.discard_holo_dark,
            context.getString(R.string.ui_cancel),
            PendingIntent.getService(context, 0, cancel, PendingIntent.FLAG_UPDATE_CURRENT));
    return b.build();
}

I tried the default NotificationBuilder on JellyBean as well. Also been trying to change PendingIntent to getActivity and tried to replace icons and text as well. Tried to setOngoing(false), without progress and with autoCancel. Still no luck seings by buttons. Tried on four different devices.

like image 276
Yaroslav Mytkalyk Avatar asked Dec 01 '22 20:12

Yaroslav Mytkalyk


1 Answers

NotificationCompat.Builder will not show Actions on Android < 4.1

On some devices, if there are multiple notifications, the notification with actions appear collapsed. Swiping down on the notification with two pointers gesture expands the actions.

like image 150
Yaroslav Mytkalyk Avatar answered Dec 10 '22 13:12

Yaroslav Mytkalyk