Load image from url in notification Android

前端 未结 8 807
北海茫月
北海茫月 2020-11-28 21:48

In my android application, i want to set Notification icons dynamically which will be loaded from URL. For that, i have used setLargeIcon property of Notificati

8条回答
  •  眼角桃花
    2020-11-28 22:20

    you can do this using Glide like this:

    val notificationBuilder = NotificationCompat.Builder(this, channelId)
            .setSmallIcon(R.drawable.ic_message)
            .setContentTitle("title")
            .setContentText("text")
    
    val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    
    val futureTarget = Glide.with(this)
            .asBitmap()
            .load(photoUrl)
            .submit()
    
    val bitmap = futureTarget.get()
    notificationBuilder.setLargeIcon(bitmap)
    
    Glide.with(this).clear(futureTarget)
    
    notificationManager.notify(0, notificationBuilder.build())
    

提交回复
热议问题