Firebase推送通知 - 如何在通知中显示多行消息

Sop*_*hie 14 android push-notification firebase firebase-cloud-messaging

获取推送通知message仅在一行中,而我期望它multiple lines与with BigPictureStyleBase(两种通知样式).

请参阅随附的屏幕截图,而在此图像中,我们只是显示,"Hello from Firebase Cloud Messaging"因此这适合单行本身.

但事实是,如果我试图表现出"你好,从火力地堡云端通讯,并再次向您问好火力地堡云通讯"即使这样,我得到的消息中single line only三个点,在这样的结尾......

在此输入图像描述

以下是我使用part代码所需:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setLargeIcon(image)/*Notification icon image*/
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(messageTitle)
                .setContentText(messageBody)
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(image)
                        .setBigContentTitle(messageTitle)
                        .setSummaryText(Html.fromHtml(messageBody)
                        .toString()))/*Notification with Image*/
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
Run Code Online (Sandbox Code Playgroud)

注意:同样的问题,我随时都会面对,我发送没有大图像的消息(基本/简单推送通知)

看这个截图:

在此输入图像描述

那么,唯一关注的如何在通知中显示多行消息?.

Dus*_*Dus 11

你几乎拥有它,你只需要设置bigText属性.

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setAutoCancel(true);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle("Title");
    bigTextStyle.bigText("Lorem ipsum dolor sit amet, consectetur adipiscing elit," +
            " sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
            "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris " +
            "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in.");

    notificationBuilder.setStyle(bigTextStyle);

    NotificationManager mNotifyMgr = (NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.notify(1, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)

多


Nik*_*hav 5

尝试这个:-

NotificationCompat.Builder builder = new NotificationCompat.Builder(
        context);
Notification notification = builder.setContentIntent(contentIntent)
        .setSmallIcon(icon).setTicker(appname).setWhen(0)
        .setAutoCancel(true).setContentTitle(appname)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
        .setContentText(message).build();

notificationManager.notify(0, notification);
Run Code Online (Sandbox Code Playgroud)