Android開發Notification右邊加大圖標顯示網絡圖片

想看下效果圖:

圖片上的兩儀式是網絡圖片。 第一次看見這種效果是在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即可。需要完整代碼的私信我

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章