1

I am using NotificationCompat.Builder to make a simple notification, which is then added to the notification bar. On an AVD running API 17, the notification can be seen in the notification pull-down as expected. But on an AVD running API 13, the title/text/info of the notification cannot be seen (possibly due to black text against the black background).

In searching for a solution to my problem, I found the following: Custom notification colors and text colors But this seems to apply only in the case of using a custom layout for the notification.

Here is my code:

    private static int notificationId = 1;
private void displayNotification() {

    // create an Intent to launch the Show Notification activity
    // (when user selects the notification on the status bar)
    Intent i = new Intent(this, ShowNotificationActivity.class);
    // pass it some value
    i.putExtra(ShowNotificationActivity.NOTIF_ID, notificationId);

    // wrap it in a PendingIntent
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, i, 0);

    // create the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("This is the Title #" + notificationId);
    builder.setContentText("This is the Text");
    builder.setContentInfo("This is the Info");
    builder.setContentIntent(pendingIntent);
    builder.setSmallIcon(android.R.drawable.ic_notification_overlay);
    builder.setAutoCancel(true);
    Notification notif = builder.build();

    // display the notification
    NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    nm.notify(notificationId, notif);

    notificationId++;
}

I had hoped to post some screen shots showing the notification pull-down under API 17 and under API 13, but apparently I don't have sufficient 'reputation points' to post images. So I guess a written description will have to suffice:

Under API 17, the notification pull-down shows the notification's icon (a red dot), title, and text. The background color is black, and the text color is white.

Under API 13, only the icon (red dot) is visible. The background color is black, I suspect the text color may be black as well.

I suspect that I am missing something obvious, but I am new to this and would appreciate any pointers.

Community
  • 1
  • 1
Clo Knibbe
  • 369
  • 2
  • 10

1 Answers1

1

When I copy-pasted your code into my empty activity I got several errors(it seems your code is incomplete). I added these lines to make it work:

int notificationId = 1;
Intent intent = new Intent(this, MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

//Here goes your code.

I just tested your code on a 3.2 emulator and this is what the notification looks like:

enter image description here

Which, I believe, is what it should look like.

Coult you test with my code and let me know if it works?

Anton Cherkashyn
  • 5,719
  • 6
  • 43
  • 80
  • Thanks for your response, Anton. In a (mis-guided) attempt at brevity, I omitted some of the code. I have added that code to the my post. It differs from yours in some minor details, which I think have no bearing on this issue. – Clo Knibbe Feb 27 '13 at 21:36
  • I have tried my sample with your code, and I still observe the same behavior (can't see title and text in pull-down). (The screen shot you show is what I expect to see.) I have tried on a few different AVDs emulating 3.2, but I get the same behavior on all of them. I feel like I'm stumbling around in the dark when I am making AVDs, could you please provide me the details of the AVD you used? – Clo Knibbe Feb 27 '13 at 21:41
  • It's unlikely that the problem is with AVD, but let's check. Can you run a different app that creates a notification and check if it's text looks right? I.e. set up an alarm and snooze it when it goes off - you will see an alarm notification. – Anton Cherkashyn Feb 27 '13 at 22:06
  • I set an alarm, using the clock program, and then I snoozed it. In the notification bar I see an entry for the snoozed alarm. I can see the icon (little white clock), but no other details. (I would post a screen shot, but I don't have sufficient privileges.) – Clo Knibbe Feb 27 '13 at 22:25
  • As an aside: I have created 3 3.2 AVDs. Inexplicably (to me, at least), two of them have a black background in the notification pull-down, and one has a white background. I can see my notifications in the AVD with the white background. – Clo Knibbe Feb 27 '13 at 22:28
  • Interesting, so the problem is indeed with the emulator. First of all, check if there are updates available for Android SDK, Android sdk tools, Platform tools and 3.2 SDK Platform. Here are the settings I used when creating an avd: Device: 10.1" WXGA 1280x800, mdpi; Target: API Level 13; CPU/ABI: ARM; RAM: 512; VM Heap: 32; Internal Storage: 200 – Anton Cherkashyn Feb 27 '13 at 22:42
  • Hmmm. Now I can't reproduce the 3.2 AVD with the white background in the notification pull-down. Perhaps I was unknowingly using a 4.x AVD when I saw the white background. – Clo Knibbe Feb 27 '13 at 22:46
  • According to the Android SDK Manager there are no updates available. I will try your AVD settings next. Thanks for you continued help. – Clo Knibbe Feb 27 '13 at 22:49
  • I made an AVD with your settings. On that AVD I can see my notifications as expected. I am happy about that, but I'm not sure how to proceed. The AVDs that I had made were all for phones, not tablets, but I don't see why that should matter. How can I determine which Device Definitions to use to make an AVD with a given API level? – Clo Knibbe Feb 27 '13 at 23:07
  • A possible clue: the Device Definition I used to make my AVDs was a user-created device. It was based on a generic device, plus a DPad. I will experiment with more of the generic devices, to see if I can further isolate my problem. – Clo Knibbe Feb 27 '13 at 23:11
  • btw, I'm calling it quits for today. Thanks again for your help with this, I really appreciate it. – Clo Knibbe Feb 27 '13 at 23:13
  • Android 3.*, also known as Honeycomb( http://developer.android.com/about/versions/android-3.0-highlights.html ) was never designed to be installed on phones, it was specifically designed for tablets. There is no way to tell how it will behave on a phone-sized screen, and I don't think you should use an emulator like that. But that only goes for Android 3.*, all other versions should handle all screen sizes just fine. – Anton Cherkashyn Feb 27 '13 at 23:15
  • Ah, that's it! I knew Honeycomb/3.x was for tablets, but I didn't think about that when creating my 3.x AVDs. Thanks so much! – Clo Knibbe Feb 28 '13 at 00:19