Question

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.

Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top