jinanwow
jinanwow

Reputation: 509

Android Development Notification Icon Issues

I am running into a strange issue with notification icons in my application.

My application sends and receives data via bluetooth. When the application is started it creates a notification icon of the application (icon.png). It will then see there is no bluetooth device connected and change the icon to (warn.png). The issue is, when the status bar at the top shows warn.png, under the on-going notification drop down it has the origional icon (icon.png) with the text "No Bluetooth Device connected". When a bluetooth device does connect, the status bar icon changes back to the origional icon (icon.png) but under the on-going notification it has the warn icon with the message "Connection Established".

Below is the code I used:

private void notification_updates(String DISPLAY_TEXT, String ONGOING_TEXT, int ICON) {
Intent intent = new Intent(this,GUI.class);
intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_SINGLE_TOP);

try
{
    notification.setLatestEventInfo(Monitor.this, "App_Name",ONGOING_TEXT, 
            PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
    notification.icon = ICON;
    notification.tickerText = DISPLAY_TEXT;
    notification.flags = notification.FLAG_ONGOING_EVENT; //on going events
    notification.flags += notification.FLAG_NO_CLEAR; //no clear.

    mManager.notify(APP_ID, notification);

} catch(Exception e)
{
    Log.e(TAG, "Failed to Notifiy the notification manager (create):\n" + e.toString());
}

}

Upvotes: 1

Views: 1501

Answers (1)

brack
brack

Reputation: 707

Try creating a whole new notification, and see if that properly updates the icon in the content view.

Alternatively, if that doesn't do it for you, create a custom content view: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView

Then, on your RemoteViews object, setImageViewResource to update your icon, setTextViewText to update the text, and set the notification.contentView to be your RemoteViews object. I've had success with this properly updating both the icon in the status bar, as well as the icon/text in the expanded task bar.

Tangentially, I noticed your code has notification.flags += notification.FLAG_NO_CLEAR. I believe since this is a bitmask you want |= instead of +=

Upvotes: 1

Related Questions