Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Wear notification prevent blinking icon when updating

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 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:
How can I avoid blinking notification update while changing button
Updating an ongoing notification quietly
How to properly update a notification post api 11?

like image 673
LearnDriver Avatar asked Dec 11 '14 19:12

LearnDriver


Video Answer


1 Answers

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.

like image 176
barwnikk Avatar answered Sep 21 '22 05:09

barwnikk