NotificationCompat.Builder largeIcon does not fit

  Kiến thức lập trình

i am stuggeling with setting of largeIcon in a notification
i found that the size of the large icon is 192×192 but the image i want to display is a pin icon with a size of (WxH) 174×290.
So…scale it is or so i thought.
i used the below code to scale my png keeping the W:H ratio.

    var bitmap = BitmapFactory.decodeResource(resources, R.mipmap.pin_bus)
    val largeIconHeight: Int = resources.getDimension(android.R.dimen.notification_large_icon_height).toInt()
    val largeIconWidth:  Int = (bitmap.width * (largeIconHeight.toFloat() / bitmap.height.toFloat())).toInt()
    val scaledBitmap = Bitmap.createScaledBitmap(bitmap, largeIconWidth, largeIconHeight, false)

The result is the screen below.
enter image description here

Does anybody know how i can scale the bitmap to fit the largeicon while maintaining the W:H ratio?

LEAVE A COMMENT