可以在大文本通知中将扩展通知设置为默认值吗?

Huy*_*wer 38 notifications android android-notifications android-styles

我遵循了这个示例代码

Big Text Notifications部分中,他说需要扩展才能看到Big text notification形式,如下图所示:

在此输入图像描述

我不知道我们做不到 set Expanded Notification as default in Big Text Notifications?

知道它的人是否可以,

如果能,

请告诉我怎么做,

谢谢,

Ema*_*lin 47

文档状态:

通知的大视图仅在通知展开时出现,当通知位于通知抽屉的顶部时,或者当用户使用手势展开通知时,会发生通知.

所以我的答案是否定的,你不能默认扩展它.

然而,有一个技巧可以将通知推送到列表的顶部,在那里它将被扩展.只需将优先级设置Notification.PRIORITY_MAX为,您的应用程序通知可能会将其设置为顶部.

  • 我会警告不要将您的通知推送到顶部,只是为了扩展它们.您的优先级应基于用户界面指南 - https://material.google.com/patterns/notifications.html#notifications-settings-priority.否则,您很可能会扰乱您的用户. (2认同)

Pon*_*ung 12

Notification noti = new Notification.Builder()
... // The same notification properties as the others
.setStyle(new Notification.BigPictureStyle().bigPicture(mBitmap))
.build();
Run Code Online (Sandbox Code Playgroud)

你改变了

.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert))
Run Code Online (Sandbox Code Playgroud)

随着公告

notification = new NotificationCompat.Builder(context)
Run Code Online (Sandbox Code Playgroud)

这是一个例子:

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

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);
Run Code Online (Sandbox Code Playgroud)