我目前已經造成的事實,NotificationCompat不支持setSmallIcon一個圖標,而不是資源ID這WET代碼:setSmallIcon(圖標:圖標),並NotificationCompat
val notification = if (Build.VERSION.SDK_INT < 23) {
NotificationCompat.Builder(this)
.setLargeIcon(bitmap)
.setSmallIcon(R.drawable.ic_launcher)
.setContentText(intentDescriber!!.userFacingIntentDescription)
.setContentTitle(label)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.build()
} else {
Notification.Builder(this)
.setSmallIcon(Icon.createWithBitmap(bitmap))
.setLargeIcon(bitmap)
.setContentText(intentDescriber!!.userFacingIntentDescription)
.setContentTitle(label)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.build()
}
有沒有一種方法,使這個更好(DRY?) - 問題在於兩個構建器類都不同。
圖標類SDK 23被引入,所以COMPAT不能支持它。 – lionscribe
但它可能需要一個位圖,並在23個IMPL它可以使用圖標和包裹位圖這個SDK級以上 – ligi
你總是可以使自己的器類... – lionscribe