Также после добавления стиля .setStyle(new Notification.DecoratedCustomViewStyle()) из DecoratedStyle выше Android 12
Вот код custom_notification.xml
Код: Выделить всё
Код: Выделить всё
class MainActivity : AppCompatActivity() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val CHANNEL_ID = "my_channel_01"
val remoteViews = RemoteViews(packageName, R.layout.custom_notification)
remoteViews.setTextViewText(R.id.title, "Title")
remoteViews.setTextViewText(R.id.text, "Text for the notification")
val mBuilder: NotificationCompat.Builder =
NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(remoteViews)
.setCustomBigContentView(remoteViews)
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
val notificationManager = getSystemService(
Context.NOTIFICATION_SERVICE
) as NotificationManager
notificationManager.notify(111, mBuilder.build())
}
Код: Выделить всё
> To show notifications above Android 12
> I think its useless, will check it again if this permission is needed or not
Подробнее здесь: https://stackoverflow.com/questions/786 ... roid-12-13