bug
版本更新时,8.0以上的手机在通知栏中不显示进度,报错信息为
Failed to post notification on channel "null".
解决方案
给显示通知的地方添加渠道信息
修复方案
重新编译显示通知的class文件,并进行替换
开始修复
- 基于crashreport_upgrade-1.3.6.aar版本。
步骤一
在Application中添加
if (Build.VERSION_CODES.O <= android.os.Build.VERSION.SDK_INT) {
val channel = NotificationChannel(
"001",//渠道ID,后续用到
"my_channel", //渠道名称,
NotificationManager.IMPORTANCE_DEFAULT
)
channel.enableLights(true) //是否在桌面icon右上角展示小红点
channel.lightColor = Color.GREEN //小红点颜色
channel.setShowBadge(true) //是否在久按桌面图标时显示此渠道的通知
nm.createNotificationChannel(channel)
}
步骤二:定位
下载bugly的aar包,解压并找到显示通知栏的所在class。
最终确定显示通知的位置在 com.tencent.bugly.beta.ui.c中,也就是c.class。
步骤三:重新编译
在as中,复制反编译后的文件,在自己工程中创建同样包名的文件,也就是com.tencent.bugly.beta.ui.c.java,在里面找到对应位置添加this.k.setChannelId("001");(三个方法都有)
this.k.setChannelId("001"); //添加的。。001对应前面添加的渠道ID
this.g = this.k.build();//原有
this.f.notify(1001, this.g);//原有
把下载下来的crashreport_upgrade-1.3.6.aar放进libs中,在gradle中配置使用aar。注意,在aar中需要把对应的a.class移除,否则会类冲突了。相当于自己写的这个,替换掉了arr中的这个类。
dependencies {
// implementation 'com.tencent.bugly:crashreport_upgrade:1.3.6'
implementation(name:'crashreport_upgrade-1.3.6',ext:'aar')
}
repositories {
flatDir {
dirs 'libs'
}
}
执行编译,编译成功后,在app/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/tencent/bugly/beta/ui中找到编译后的c.class,重新加进arr库中,把本地的反编译的删掉,就大功告成了
结尾
更希望的还是bugly那早点修复这个bug吧
修改后的aar包: 链接: https://pan.baidu.com/s/1SAlijAfbd8CFhkawAGqNzg 提取码: 3fkx