18

I use the NotificationCompat.Builder to display my notification through android versions and use a custom layout for the notification.
The custom layout works fine on Android 3 and up (API Level 11), but don't show up on API Level 10 or lower. I tested it on 2.3 and 2.2 in the Emulator.

Heres my code:

    Builder builder = new NotificationCompat.Builder(getApplicationContext());

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
    contentView.setImageViewResource(R.id.notImage, R.drawable.stat_icon);
    contentView.setTextViewText(R.id.notTitle, getResources().getString(R.string.streamPlaying));
    contentView.setTextViewText(R.id.notText, StartActivity.streamName + " " + getResources().getString(R.string.playing));

    builder
            .setContentTitle(getResources().getString(R.string.streamPlaying))
            .setContentText(StartActivity.streamName + " " + getResources().getString(R.string.playing))
            .setSmallIcon(R.drawable.stat_icon)
            .setContentIntent(pendingIntent)
            .setOngoing(true)
            .setWhen(0)
            .setTicker(StartActivity.streamName + " " + getResources().getString(R.string.playing))
            .setContent(contentView);

    not = builder.build();

really basic. The layout file is correct, its the same as in the notification tutorial on android.com, to make sure I didn't make a mistake in there. ;)
Remember: Working fine on 3.0 and up, but not at 2.3 and lower.

Leandros
  • 16,805
  • 9
  • 69
  • 108

1 Answers1

38

This may be a bug in the support library - see this issue.

You may have to work around it by applying the contentView directly:

not.contentView = contentView;
UgglyNoodle
  • 3,017
  • 1
  • 21
  • 17
  • 3
    Layout works so far on 2.3 and lower, but I can't click the button which I added. This works only on Android 3 and higher... – Leandros Sep 25 '12 at 13:35
  • 3
    @Leandros, support for clicking buttons in notifications was not added until Android 3.0. – Justin May 11 '13 at 16:51
  • Thanks UgglyNoodle! I tried everything to get this to work. You'd think they'd document the bug in the SDK docs so we'd know! – JeffG Oct 21 '13 at 16:32