Android 7.0+ notification更新progr
2018-07-19 本文已影响33人
stormKid
代码:
fun updateProgress(process: Int) {
val notify = notifyContents[notifyId]?:return
if (Build.VERSION.SDK_INT >= 24){
val build = Notification.Builder.recoverBuilder(context,notify)
build.setProgress(100,process,false)
getManager().notify(notifyId,notify)
}else{
notify.contentView.setProgressBar(android.R.id.progress,100,process,false)
getManager().notify(notifyId,notify)
}
}
说明:
根据源码注释,找到更新此notification的进度条方法:
![](https://img.haomeiwen.com/i4253553/741cb1dad961aebd.png)
contentView在N 以上都为null,我们可以根据提示的方法找到对应的build,然后根据build获取build来更新UI组件,达到我们更新notification的进度条的目的。