AppUpdate
AppUpdate copied to clipboard
android 0通知栏无法显示
当compileSdkVersion设置为26时,在android o上运行下载的那个通知栏消息不显示,需要加一个channelId
fun sendNotification(context: Context, title: String, text: String, intent: Intent? = null) {
val channelId = "default"
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
NotificationCompat.Builder(context, channelId)
else {
NotificationCompat.Builder(context)
}
builder.setContentTitle(title)
.setContentText(text)
.setAutoCancel(true)
.setTicker(text)
.setWhen(System.currentTimeMillis())
.setOngoing(false)
.setDefaults(Notification.DEFAULT_VIBRATE)
.setSmallIcon(R.mipmap.ic_launcher)
intent?.let {
if (context !is Activity) {
intent.flags = intent.flags or Intent.FLAG_ACTIVITY_NEW_TASK
}
val pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
builder.setContentIntent(pendingIntent)
}
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannel(createChannel(channelId))
}
notificationManager.notify(Random().nextInt(), builder.build())
}
@RequiresApi(Build.VERSION_CODES.O)
private fun createChannel(channelId: String): NotificationChannel? {
return NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_DEFAULT)
}
作者有时间时可以解决下吗,谢谢
@typ0520 应用安装闪退的问题解决了么?能不能提供点经验呢?关于8.0 类似:https://github.com/yjfnypeu/UpdatePlugin/issues/51