在大字体通知中是否可以将扩展通知设置为默认选项?

46

我按照示例代码进行了操作。

大文本通知一节中,他说需要展开才能看到如下图片中的大文本通知表单:

enter image description here

我想知道我们是否可以在大文本通知中将展开通知设置为默认?

知道的人麻烦告诉我怎么做,谢谢!


您可以通过实现自定义通知并设置所需高度来更改它。如果需要,我可以提供示例。 - Dejan
@DjDexter请提供答案以便大家知道。如果它真的有用,人们和我也会投票。 - Huy Tower
请阅读这个惊人的答案: https://dev59.com/JmMl5IYBdhLWcg3woYMv#18603076 - Stav Bodik
5个回答

55

文档说明如下:

通知的大视图仅在通知被展开时显示,这发生在通知位于通知抽屉的顶部,或者当用户使用手势展开通知时。

所以我的答案是不能默认展开它。

然而,有一个技巧可以将通知推到列表的顶部并展开。只需将优先级设置为Notification.PRIORITY_MAX,你的应用程序通知很可能会出现在顶部。


当您停车后,Automatic应用程序似乎已经预先展开。 - Dave Jensen
如果设置了P_MAX,则通知将显示为悬浮通知。此外,当我尝试使用Pushbullet连接USB并超过移动数据限制时,通知仍然在顶部。您是否有解决方法,因为这似乎没有达到预期的结果。 - Japes
不再在现场 - >> 只有当通知被展开时,通知的大视图才会出现,这仅在通知位于通知抽屉的顶部或用户使用手势展开通知时发生。 - Abhigyan
2
我建议不要将通知推到顶部,只是为了让它们扩展。你的优先级应该基于UI指南-https://material.google.com/patterns/notifications.html#notifications-settings-priority。否则,你很可能会让用户感到不满。 - Bourne
我的大文本重叠在小文本上。这不会在单击时扩展。 - IntoTheDeep
显示剩余4条评论

14
Notification noti = new Notification.Builder()
... // The same notification properties as the others
.setStyle(new Notification.BigPictureStyle().bigPicture(mBitmap))
.build();

你改变

.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))

随着宣布一起

notification = new NotificationCompat.Builder(context)

这里是一个例子:

输入图像描述您可以设置代码

Intent intent = new Intent(context, ReserveStatusActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
intent = new Intent(String.valueOf(PushActivity.class));
intent.putExtra("message", MESSAGE);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(PushActivity.class);
stackBuilder.addNextIntent(intent);
// PendingIntent pendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

// android.support.v4.app.NotificationCompat.BigTextStyle bigStyle = new     NotificationCompat.BigTextStyle();
// bigStyle.bigText((CharSequence) context);

notification = new NotificationCompat.Builder(context)
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(th_title)
    .setContentText(th_alert)
    .setAutoCancel(true)
 // .setStyle(new Notification.BigTextStyle().bigText(th_alert)  ตัวเก่า
 // .setStyle(new NotificationCompat.BigTextStyle().bigText(th_title))
    .setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))
    .setContentIntent(pendingIntent)
    .setNumber(++numMessages)
    .build();

notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationManager.notify(1000, notification);

1
我的大文本重叠了小的。这不会在单击时扩展。 - IntoTheDeep

1
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText("Your Long Text here"))

简单地在您的通知构建器中设置setStyle

0

从这个通知代码中,您可以获取图像、大文本或更多内容。

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mBuilder.setSmallIcon(R.drawable.small_logo);
                mBuilder.setColor(Color.parseColor("#D74F4F"));
            } else {
                mBuilder.setSmallIcon(icon);
            }

            mBuilder.setTicker(title).setWhen(when);
            mBuilder.setAutoCancel(true);
            mBuilder.setContentTitle(title);
            mBuilder.setContentIntent(intent);
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), icon));
            mBuilder.setContentText(msg);
            mBuilder.setPriority(Notification.PRIORITY_MAX);
            if (Utils.validateString(banner_path)) {
                mBuilder.setStyle(notiStyle);
            } else {
                mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
            }

            Notification noti = mBuilder.build();
            notificationManager.notify(0, noti);

“notiStyle”的作用是什么?“validateString”是什么? - android developer
NotiStyle 是一个 NotificationCompat.BigPictureStyle,而 validateString 只是检查您的字符串值是否有效。 - Jackey kabra
请问您能把那些也放在这里吗? - android developer

0
在使用Push Notification V5时,无需对任何文件进行修改即可显示多行通知。只需从您发送的对象中删除“style”字段即可自动显示多行通知。如需更多信息,请点赞此答案并提出您的问题。我会帮助您解决。
参考链接:访问此问题

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接