Android Wear notification prevent blinking icon when updating

AndroidWear OsAndroid Wear-Notification

Android Problem Overview


I can't seem to be able to create an Android Wear notification that updates with out blinking the app icon whereas the same code works fine on an Android phone.

Most referenced solutions talk about updating the same notification, use setAlertOnlyOnce, keeping the ID or when the same. However, whatever I do, every time the notification is updated it blinks (most noted by the App Icon).

As suggested here https://stackoverflow.com/questions/25499834/android-wear-timer-like-notification-card-on-wear-device you can use setHintHideIcon(true) to hide the app icon, which hides the blinking part, however in the limited world of Android Wear Notifications the app icon plays a large part in the branding of the application.

If you want a timer, you can use .setUsesChronometer(true) and let the system update the timer which works perfectly. Unfortunately if you want to update something else than time (like steps or messages received count) it seems to me you're out of luck.

Below you can find code that works fine when run as a phone app, but blinks when run as a wearable app.

Commented line below to demonstrate that the notification still blinks (when running on wear, not the phone) that the notification still blinks when posting an unchanged notification on the wearable. Uncomment to update the notification again.

mNotification = buildNotification(WearMainActivity.this);

Therefore my question is if anyone has any further idea's we can explore to keep the notification from blinking or if we can write this down as an Android Wear bug?

public class WearMainActivity extends Activity {

    public final int NOTIFICATION_ID= 1;
    public Notification mNotification;
    public int count;
    public long when;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        count = 0;
        when = System.currentTimeMillis();
        mNotification = buildNotification(WearMainActivity.this);
        postDelayedHandler();
        finish();
    }

    private void postDelayedHandler(){

        new Handler().postDelayed(new Runnable() {
            public void run() {
                count++;
                mNotification = buildNotification(WearMainActivity.this);
                NotificationManager notifyMgr = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
                notifyMgr.notify(NOTIFICATION_ID, mNotification);
                postDelayedHandler();
            }
        }, 1000L);
    }

    private Notification buildNotification(Context context){
        return new Notification.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText("Count: "+count)
                .setWhen(when)
//                .setOngoing(true) //Don't do this, adds "Mute app" action
                .setOnlyAlertOnce(true)
                .setPriority(Notification.PRIORITY_MAX)
                .extend(new Notification.WearableExtender()
//                        .setHintHideIcon(true) //Hides the icon, so kinda hides the blink
                )
                .build();
    }
}

Tested on:
Wearable: Moto 360 (4.4W2) Wear Emulator (5.0.1)
Phones: Galaxy Nexus (4.3) and Nexus 5 (5.0.0)

Occurs: When running as a Wearable app or as phone notification displayed on Wearable. Works perfect on phone.

Referenced questions:
https://stackoverflow.com/questions/19025056/how-can-i-avoid-blinking-notification-update-while-changing-button<br/> https://stackoverflow.com/questions/6406730/updating-an-ongoing-notification-quietly<br/> https://stackoverflow.com/questions/11512986/how-to-properly-update-a-notification-post-api-11

Android Solutions


Solution 1 - Android

Replace:

NotificationManager notifyMgr = 
    ((NotificationManager)getSystemService(NOTIFICATION_SERVICE));

to:

NotificationManagerCompat notifyMgr =
    NotificationManagerCompat.from(this);

More informations: https://developer.android.com/training/wearables/notifications/creating.html

You also making a lot of updates. Every update is send via bluetooth to Wear. You should create self-install app to Android Wear. The delay of sending is about 3 seconds.

Solution 2 - Android

I solved this problem a while back when I was working with Android Wear but the code in unfortunately gone. Anyway, what I did was to not BUILD the notification every time I wanted to update it, I just tagged the notification the first time I created it and then I retrieved it with the TAG and made my changes directly to that object. That completely stopped the flickering...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLearnDriverView Question on Stackoverflow
Solution 1 - AndroidbarwnikkView Answer on Stackoverflow
Solution 2 - AndroidJoakimView Answer on Stackoverflow