【问题标题】:Is possible set Expanded Notification as default in Big Text Notifications?是否可以在大文本通知中将扩展通知设置为默认值?
【发布时间】:2014-06-13 10:39:46
【问题描述】:

我关注了这个Sample Code

Big Text Notifications部分,他说需要展开查看Big text notification表格,如下图:

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

知道它是否可以的人,

如果可以的话,

请告诉我怎么做,

谢谢,

【问题讨论】:

  • 您可以通过实现自定义通知来更改它,并根据需要设置高度。如果你愿意,我可以写例子。
  • @DjDexter 请让人们知道答案。如果它真的有用,人们和我也会投票。
  • 请阅读这个惊人的答案:stackoverflow.com/a/18603076/4120180

标签: android notifications android-notifications android-styles


【解决方案1】:

documentation states:

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

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

但是,有一个技巧可以将通知推送到列表顶部,以便展开。只需将优先级设置为Notification.PRIORITY_MAX,您的应用程序的通知就有可能出现在顶部。

【讨论】:

  • 好的,谢谢。看起来谷歌只允许Gmail应用程序可以默认显示这个Big Text Style,如果只有它显示在通知栏上。
  • IMO Gmail 至少不会在我刚刚测试的设备(仅限 Nexus 设备)上扩展其通知。顺便说一句,您可以尝试将通知推送到列表顶部,以便它们得到扩展。不是 100% 可靠,但总比没有好(我相应地更新了我的答案)。
  • “列表的顶部将被扩展” - 是的,你是对的。 Android 4.1 支持的设备可以显示Big Text Style。我的 Galaxy S3 可以显示它,而不仅仅是 Nexus 设备。
  • 自动应用似乎在您停好车后预先展开。
  • 我会警告不要将您的通知推到顶部,以便它们被扩展。您的优先级应基于 UI 指南 - material.google.com/patterns/…。否则,您很可能会惹恼您的用户。
【解决方案2】:
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);

【讨论】:

  • 我的 BigText 重叠很小。这不是点击展开
【解决方案3】:
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText("Your Long Text here"))

只需 setStyle 通知生成器。

【讨论】:

    【解决方案4】:

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

    供参考,visit this question

    【讨论】:

      【解决方案5】:

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

      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 ?
      • NotiStyle 是 NotificationCompat.BigPictureStyle 和 validateString 只是检查您的字符串值是否有效。
      • 你能把这些也放在这里吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 2019-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      相关资源
      最近更新 更多