'BigTextStyle doesn't work when used with BigPictureStyle in notification (Kotlin)

When I use BigTextStyle and BigPictureStyle together, only setContentText and BigPictureStyle are shown in the notification drawar. I mean if the text is long, it won't show the full text (BigTextStyle doesn't seem to work at all) It shows the same on my phone (Android 11), Does anyone know how I can solve this problem?

private fun sendNotification() {

    val intent = Intent(this, MainActivity::class.java)
    val pendingIntent: PendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)

    val bitmap = BitmapFactory.decodeResource(applicationContext.resources, R.drawable.wallet)
    val bitmapLargeImage = BitmapFactory.decodeResource(applicationContext.resources, R.drawable.sell)

    val builder = NotificationCompat.Builder(this, CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_baseline_attach_money_24)
        .setContentTitle("Purchase")
        .setContentText("This is the text I want to show to my users in the notification bar, but it is not fully shown.")
        .setContentIntent(pendingIntent)
        .setStyle(NotificationCompat.BigTextStyle().bigText("This is the text I want to show to my users in the notification bar, but it is not fully shown."))
        .setStyle(NotificationCompat.BigPictureStyle().bigPicture(bitmapLargeImage))
        .setLargeIcon(bitmap)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
    with(NotificationManagerCompat.from(this)) {
        notify(notificationID, builder.build())
    }
}


Solution 1:[1]

Wanted to post a comment but don't have enough reputation.

As far as I know you cannot use BigTextStyle with BigPictureStyle, by default.

To do that, you need to create a Custom View for your notification

See the documentation on how to create a Custom View for a notification: https://developer.android.com/training/notify-user/custom-notification

Maybe this similar stackoverflow question can help: How to use both BigTextStyle and BigPictureStyle in setStyle Notification?

While this may not be a problem for you, for apps that target Android 12 some behaviours for fully custom notifications change - See https://developer.android.com/about/versions/12/behavior-changes-12#custom-notifications

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pedro Bilro