Android Wear通知在更新时防止闪烁图标

我似乎无法创build一个Android Wear通知,更新闪烁的应用程序图标,而相同的代码在Android手机上正常工作。

大多数引用的解决scheme都是关于更新相同的通知,使用setAlertOnlyOnce ,保持ID或相同的时间。 但是,无论我做什么,每次通知更新时都会闪烁(最常见的是App图标)。

正如这里所build议的Android Wear:穿戴设备上的定时器像通知卡,您可以使用setHintHideIcon(true)来隐藏应用程序图标,这隐藏了闪烁的部分,但是在Android Wear Notifications的有限世界中,应用程序图标在品牌的应用程序。

如果你想要一个计时器,你可以使用.setUsesChronometer(真) ,让系统更新完美的计时器。 不幸的是,如果你想更新的东西比时间(如步骤或消息收到计数)在我看来,你是运气不好。

下面你可以find代码,当作为手机应用程序运行时工作正常,但作为可穿戴应用程序运行时闪烁。

在下面的评论线表明,通知仍然闪烁(在穿戴时运行,而不是在电话上)通知在可穿戴设备上发布未改变的通知时仍然闪烁。 取消注释以再次更新通知。

mNotification = buildNotification(WearMainActivity.this); 

因此,我的问题是,如果任何人有任何进一步的想法,我们可以探讨保持眨眼的通知,或者如果我们可以把这写成一个Android Wear错误?

 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(); } } 

testing:
可穿戴式:Moto 360(4.4W2)Wear Emulator(5.0.1)
手机:Galaxy Nexus(4.3)和Nexus 5(5.0.0)

发生时:作为可穿戴应用程序运行时,或作为佩戴式服务器上显示的电话通知运行。 在手机上完美工作。

参考问题:
如何避免在更改button时闪烁通知更新
悄悄地更新正在进行的通知
如何正确更新通知后的API 11?

更换:

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

至:

 NotificationManagerCompat notifyMgr = NotificationManagerCompat.from(this); 

更多信息: https : //developer.android.com/training/wearables/notifications/creating.html

你也做了很多更新。 每个更新都通过蓝牙发送到Wear。 您应该为Android Wear创build自我安装应用。 发送延迟大约3秒。

在我使用Android Wear的时候,我解决了这个问题,但是不幸的是代码不见了。 无论如何,我所做的就是在每次想要更新通知时都不会build立通知,我只是在第一次创build通知的时候标记了通知,然后用TAG检索了通知,并直接对该对象进行了更改。 这完全停止了闪烁…