美文网首页
Android开发Notification右边加大图标显示网络图

Android开发Notification右边加大图标显示网络图

作者: 你的益达233 | 来源:发表于2021-11-01 16:29 被阅读0次

想看下效果图:

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即可。需要完整代码的私信我

相关文章

网友评论

      本文标题:Android开发Notification右边加大图标显示网络图

      本文链接:https://www.haomeiwen.com/subject/ryozaltx.html