Reputation: 2255
The Code A is from a sample project.
Is Code A correct?
Is Code B correct?
Is there a better way to set flags of NotificationChannel ?
Code A
val notification = builder.build()
notification.flags = notification.flags or NotificationCompat.FLAG_ONGOING_EVENT //I think it will be overwrite.
notification.flags = notification.flags or NotificationCompat.FLAG_NO_CLEAR
Code B
val notification = builder.build()
notification.flags = notification.flags or NotificationCompat.FLAG_ONGOING_EVENT or NotificationCompat.FLAG_NO_CLEAR
Both
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel = NotificationChannel(
CHANNEL_ID,
mChannelName,
NotificationManager.IMPORTANCE_LOW
)
notificationManager.createNotificationChannel(notificationChannel)
NotificationCompat.Builder(this, notificationChannel.id)
} else {
NotificationCompat.Builder(this)
}
Upvotes: 0
Views: 510
Reputation: 5214
See you again :-)
NotificationCompat.FLAG_ONGOING_EVENT
has value 2
, NotificationCompat.FLAG_NO_CLEAR
has value 32
.NotificationCompat.FLAG_*
we can realize that many of them are power of 2.or
.Then, your question
//I think it will be overwrite.
It won't be overwritten. They are all kept by the operator or
.
- Is Code A correct?
- Is Code B correct?
If the sample code is correct, then BOTH A and B are correct.
Upvotes: 1