Уведомление не отображается на некоторых устройствах - PullRequest
0 голосов
/ 16 июня 2019

Я пытаюсь проверить работоспособность push-уведомлений на разных устройствах.Теперь, когда я использую Samsung Galaxy S9 + с android Pie, уведомление показывается как надо - я вижу заголовок, вижу тело и вижу значок.При тестировании на Galaxy S8 с Android Pie я не вижу ни названия, ни тела, появляется только значок.При тестировании на Pixel 2XL с Android Oreo поведение такое же, как с Galaxy S9 +, однако при тестировании на Pixel 2XL с Android поведение такое же, как на Galaxy S8.Что может вызвать изменение поведения на разных устройствах?Как я могу это исправить?

Вот код, который я использую, чтобы показать

private void showNotifications(String title, String msg, String deepLink){
        msg = msg.replace("<br/>", "\n");
        Spanned htmlText = Html.fromHtml(msg);
        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_push);
        contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher_foreground);
        contentView.setTextViewText(R.id.title, title);
        contentView.setTextViewText(R.id.text, htmlText);

        Intent intent ;

        if (deepLink!=null)
            intent = new Intent(deepLink);
        else
            intent = new Intent(this, MainActivity.class);

        //get desired location from deep link
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.putExtra("title", title);
        intent.putExtra("message", msg);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);


        Random rand = new Random();
        int  notificationID = rand.nextInt(50000);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

            NotificationCompat.Builder notification = new NotificationCompat.Builder(getApplicationContext(), NOTIF_CHANNEL_ID)
                    .setContent(contentView)
                    .setContentIntent(pendingIntent)
                    .setSound(defaultSoundUri)
                    .setSmallIcon(R.drawable.status_bar_icon)
                    .setAutoCancel(true)
                    .setChannelId(NOTIF_CHANNEL_ID);

            NotificationChannel channel = new NotificationChannel(NOTIF_CHANNEL_ID, NOTIF_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
            channel.enableLights(true);
            channel.setShowBadge(true);
            channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
            channel.enableVibration(true);
            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            manager.createNotificationChannel(channel);
//            manager.notify(notificationID, notification.build());
            manager.notify(NOTIF_CHANNEL_ID, notificationID, notification.build());

        }
        else
        {
            Notification notification = new NotificationCompat.Builder(this)
                    .setContent(contentView)
                    .setContentIntent(pendingIntent)
                    .setSmallIcon(R.drawable.status_bar_icon)
                    .setSound(defaultSoundUri)
                    .setAutoCancel(true)
                    .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
                    .build();

            NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            manager.notify(notificationID, notification);
        }
    }

Вот как это должно выглядеть (вот как это выглядит на Android Pie - GalaxyS9 + и Pixel 2XL с Android Oreo) enter image description here

Так выглядит Pixel 2XL с Android Pie и Galaxy S8 с Android Pie.(Текст отсутствует в уведомлении) enter image description here

...