Lea*_*ver 53 android android-wear-notification wear-os
我似乎无法创建Android Wear通知,更新时不会闪烁应用程序图标,而相同的代码在Android手机上正常工作.
大多数引用的解决方案都涉及更新相同的通知,使用setAlertOnlyOnce,保留ID或何时相同.但是,无论我做什么,每次更新通知时它都会闪烁(最常见的是应用程序图标).
正如这里所建议的那样Android Wear:像穿戴设备上的通知卡一样,你可以使用setHintHideIcon(true)隐藏应用程序图标,隐藏闪烁的部分,但是在Android Wear Notifications的有限世界中,应用程序图标在应用程序的品牌.
如果你想要一个计时器,你可以使用.setUsesChronometer(true)让系统更新完美的计时器.不幸的是,如果你想更新别的东西而不是时间(比如收到的步骤或消息数),我觉得你运气不好.
您可以在下面找到在作为手机应用程序运行时正常运行的代码,但在作为可穿戴应用程序运行时会闪烁.
下面的注释行显示通知仍然闪烁(当在磨损时运行时,而不是电话),当在可穿戴设备上发布未更改的通知时,通知仍然闪烁.取消注释以再次更新通知.
mNotification = buildNotification(WearMainActivity.this);
Run Code Online (Sandbox Code Playgroud)
因此,我的问题是,如果有人有任何进一步的想法,我们可以探索以防止通知闪烁或我们是否可以将其写为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();
}
}
Run Code Online (Sandbox Code Playgroud)
测试:
可穿戴:Moto 360(4.4W2)磨损仿真器(5.0.1)
电话:Galaxy Nexus(4.3)和Nexus 5(5.0.0)
发生:作为可穿戴应用程序运行或作为可穿戴设备上显示的电话通知运行.在手机上完美运作.
代替:
NotificationManager notifyMgr =
((NotificationManager)getSystemService(NOTIFICATION_SERVICE));
Run Code Online (Sandbox Code Playgroud)
和:
NotificationManagerCompat notifyMgr =
NotificationManagerCompat.from(this);
Run Code Online (Sandbox Code Playgroud)
您还进行了大量更新。每次更新都会通过蓝牙发送到 Wear。您应该为 Android Wear 创建自安装应用程序。发送延迟约3秒。
归档时间: |
|
查看次数: |
1195 次 |
最近记录: |