Create fully notification android 12

990 views Asked by At

I want to custom notification like image. In android 12, my custom notification not is not fit the notification area width. How can I fix it? Here is my notification:

    val builder = NotificationCompat.Builder(this, channelId)
        .setSmallIcon(R.drawable.img_app_logo)
        .setCustomContentView(remoteViews)
        .setCustomBigContentView(remoteViews)
        .setCustomHeadsUpContentView(remoteViews)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setAutoCancel(true)
        .addAction(optimizeAction)
    cancelAction?.let {
        builder.addAction(it)
    }
    notificationManager.notify(notificationId, builder.build())

Thanks

1

There are 1 answers

0
Mahdi Jafari On

You should change the targetSdkVersion from the build.gradle file to something below 31. (30 worked for me)

More information here: https://developer.android.com/about/versions/12/behavior-changes-12