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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23331682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:01:13  来源:igfitidea点击:

Is possible set Expanded Notification as default in Big Text Notifications?

androidnotificationsandroid-notificationsandroid-styles

提问by Huy Tower

I followed this Sample Code

我遵循了这个示例代码

In Big Text Notificationssection, he said that need expand to see Big text notificationform, as image im below :

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

enter image description here

enter image description here

I wonder that we can not set Expanded Notification as default in Big Text Notifications?

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

People who know it is can or not,

知道的人能不能,

If can,

如果能,

Please tell me how to do it,

请告诉我怎么做,

Thanks,

谢谢,

回答by Emanuel Moecklin

The documentation states:

文件指出

A notification's big view appears only when the notification is expanded, which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture.

通知的大视图仅在通知展开时出现,这种情况发生在通知位于通知抽屉顶部或用户使用手势展开通知时。

So my answer is no, you can't expand it by default.

所以我的答案是否定的,默认情况下你不能扩展它。

There is however a trick to push the notification to the top of the list where it would be expanded. Simply set the Priority to Notification.PRIORITY_MAXand chances are that your app's notification will make it to the top.

然而,有一个技巧可以将通知推送到列表的顶部,在那里它会被展开。只需将 Priority 设置Notification.PRIORITY_MAX为 ,您的应用程序的通知就可能会出现在顶部。

回答by Pong Petrung

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

You change

你改变

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

along with the announcement

随着公告

notification = new NotificationCompat.Builder(context)

Here is an example:

下面是一个例子:

enter image description hereYou can set Code

enter image description here您可以设置代码

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);

回答by Nitin Agarwal

No need of doing any kind of modification in the any file for showing of multiple lines of Notification while using Push Notification V5, remove the field "style", from the object you are sending. Automatically the Multiple lines of notification will be seen. For more information, upvote the answer, ask your query. I will help you out.

使用 Push Notification V5 时,无需在任何文件中进行任何类型的修改以显示多行通知,从您发送的对象中删除字段“样式”。将自动看到多行通知。有关更多信息,请为答案投票,提出您的疑问。我会帮你的。

For reference, visit this question

作为参考,请访问此问题

回答by Hymaney kabra

From this notification code you have got images, and big text or more.

通过此通知代码,您可以获得图像、大文本或更多内容。

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);

回答by Abdurahman Popal

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

simply setStyleof your notification builder.

只是setStyle您的通知生成器。