想看下效果图:
notication.jpg图片上的两仪式是网络图片。 第一次看见这种效果是在Boss招聘app上,当时就好奇那里还能显示网络图片。
今天刚好学习到Notification,就顺便实现了
代码如下:
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as
NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel("normal", "Normal",NotificationManager.
IMPORTANCE_DEFAULT)
manager.createNotificationChannel(channel)
}
sendNotice.setOnClickListener {
val intent = Intent(this,NotificationActivity::class.java)
val pi = PendingIntent.getActivity(this,0,intent,0)
val notification = NotificationCompat.Builder(this, "normal")
.setContentTitle("This is content title")
.setContentText("This is content text")
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(imageBitmap)
.setContentIntent(pi)
.setAutoCancel(true)
.build()
manager.notify(1, notification)
}
重点是setLargeIcon。
代码中的imageBitmap没有给出,就网络图片转成bitmap即可。需要完整代码的私信我
网友评论