Уведомление неожиданно установлено в заголовок уведомления - PullRequest
0 голосов
/ 28 июня 2019

со ссылкой на этот вопрос Текст содержания уведомления изменяется в зависимости от различных сценариев , я сталкиваюсь с тем, что когда уведомление приходит, оно отображает все его сообщение и заголовок правильно, но когда я опускаю системный трей впросматривать уведомления заголовок уведомлений и сообщение становится одинаковым!Кто-нибудь может объяснить, пожалуйста, причину этого сценария?Вот код, который я реализовал -

@RequiresApi(api = Build.VERSION_CODES.O)
private void sendChatmessageNotification(String title, String message, String senderId){
    Log.d(TAG, "sendChatmessageNotification: building a chatmessage notification");

    NotificationChannel mChannel=null;

    //get the notification id
    int notificationId = buildNotificationId(senderId);

    // Instantiate a Builder object.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "default_channel_id_chat");
    // Creates an Intent for the Activity
    Intent pendingIntent = new Intent(this, MainActivity.class);
    // Sets the Activity to start in a new, empty task
    pendingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    pendingIntent.putExtra("Id", senderId);
    pendingIntent.putExtra("Name", title.split(":")[1].trim());

    // Creates the PendingIntent
    PendingIntent notifyPendingIntent =
            PendingIntent.getActivity(
                    this,
                    0,
                    pendingIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


        mChannel = new NotificationChannel("default_channel_id_chat", getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);
        // Configure the notification channel.
        mChannel.setDescription(message);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.GREEN);
        mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        mNotificationManager.createNotificationChannel(mChannel);

        //add properties to the builder
        builder.setSmallIcon(R.drawable.icons1)
                .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),
                        R.drawable.icons1))
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setContentTitle(title)
                .setContentText("test  " +message)
                .setColor(getResources().getColor(R.color.blue_btn_bg_color))
                .setAutoCancel(true)
                .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(title).setSummaryText(message))
                .setNumber(mNumPendingMessages)
                .setOnlyAlertOnce(true);

    builder.setContentIntent(notifyPendingIntent);


    mNotificationManager.notify(notificationId, builder.build());

}

private int buildNotificationId(String id){
    Log.d(TAG, "buildNotificationId: building a notification id.");

    int notificationId = 0;
    for(int i = 0; i < 9; i++){
        notificationId = notificationId + id.charAt(i);
    }
    Log.d(TAG, "buildNotificationId: id: " + id);
    Log.d(TAG, "buildNotificationId: notification id:" + notificationId);
    return notificationId;
}

Вот изображение enter image description here

...