Я пытаюсь создать собственное сообщение и во всех ситуациях, которые оно создает. Дизайн создается только после того, как сообщение попадает в ветку уведомлений Android, но в первые моменты, прежде чем оно попадет туда и отобразится в передней части экрана, сообщение отображается в соответствии с УВЕДОМЛЕНИЕМ ANDROID по умолчанию, есть ли решение создать и изменить НАЗВАНИЕ и ТЕКСТ сообщения, даже если оно находится в передней части экрана, или изменить настройки по умолчанию?
Это мой код: custom_notification.xml
Это мой Java-код:
private void showCustomNotification(Context context, String title, String message) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "custom_channel_id";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Custom Notifications", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
RemoteViews customView = new RemoteViews(context.getPackageName(), R.layout.custom_notification);
customView.setTextViewText(R.id.custom_title, title);
customView.setTextViewText(R.id.custom_message, message);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setCustomContentView(customView)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true);
Intent intent = new Intent(context, YourActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
notificationManager.notify(1, builder.build());
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... -android-s