
首先,此问题出现在所有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)解决方法 我一直在调查.您可以做的最好的事情是创建没有频道的通知.服务从托盘中的任何内容开始.似乎适合我.
NotificationCompat.Builder(本)
但是,此构造函数在26.1.0中已弃用
总结以上是内存溢出为你收集整理的android – startForeground()总是在Samsung 8.0设备上显示一个d出窗口全部内容,希望文章能够帮你解决android – startForeground()总是在Samsung 8.0设备上显示一个d出窗口所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)