Android 8.0经常弹窗,android – startForeground()总是在Samsung 8.0设备上显示一个弹出窗口...
每次我在前台服务中使用startForeground()在其通知中进行状态更新时,我遇到三星Galaxy S7 Edge的问题,显示弹出通知.首先,此问题出现在所有Android 8.0设备上,但很容易修复,我的通知通道优先级设置为IMPORTANCE_LOW.但问题仍然存在于三星设备上.所以,问题是,如何在Samsung 8.0设备上静默更新前台服务通知?我的代码如下.申请类:override
每次我在前台服务中使用startForeground()在其通知中进行状态更新时,我遇到三星Galaxy S7 Edge的问题,显示弹出通知.
首先,此问题出现在所有Android 8.0设备上,但很容易修复,我的通知通道优先级设置为IMPORTANCE_LOW.但问题仍然存在于三星设备上.
所以,问题是,如何在Samsung 8.0设备上静默更新前台服务通知?
我的代码如下.
申请类:
override fun onCreate() {
super.onCreate()
//other code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannels(listOf(
//
NotificationChannel(MY_NOTIFICATION_CHANNEL,"My channel",NotificationManager.IMPORTANCE_LOW).apply {
setSound(null,null)
}
//
))
}
}
服务开始前景:
val notification = NotificationCompat.Builder(this,MY_NOTIFICATION_CHANNEL)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setColor(App.context().resources.getColor(R.color.primary_dark))
.setContentText(if (/*logic*/) "This" else "That")
.addAction(0,if (enable) "Disable" else "Enable",firstIntent)
.addAction(0,"Another action",secondIntent)
.build()
startForeground(MY_NOTIFICATION_ID,notification)
更多推荐
所有评论(0)