unl*_*udo 6 notifications android android-notifications
我有一个通过服务更新通知的应用程序.
此通知每秒更新一次.它显示了一个计时器.
目前在nougat上,设备已锁定,通知更新触发屏幕唤醒,以显示更新的通知.
我想控制这个,因为我的通知非常频繁.
我还想避免更改通知的更新频率.这样做会向用户显示不太准确的信息.
所以我正在寻找的是一种编程方式来控制通知更新时的唤醒屏幕频率.
谢谢 :)
下面的通知可用于频繁更新用户,并且锁定时屏幕不会唤醒。你可以尝试
if(notificationBuilder == null) {
notificationBuilder =
new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(R.mipmap.ic_launcher)
.extend(wearableExtender)
.setAutoCancel(true)
.setContentTitle("Random Notification")
.setContentText("Appears!")
.setOnlyAlertOnce(true)
.setOngoing(true)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(contentIntent);
}else{
notificationBuilder.setContentText("change this to current updated text");
}
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainActivity.this);
notificationManager.notify(888, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)