【问题标题】:Chrome extension maximum message lengthChrome 扩展最大消息长度
【发布时间】:2015-08-07 17:44:17
【问题描述】:

我正在使用谷歌浏览器通知 API。我的问题真的很简单很简短,是否可以更改通知中message的最大长度?

如果我的问题不清楚,例如:

这是我的通知选项:

var options = {
  type: "basic",
  title: title,
  message: text,
  iconUrl: "152.png"
}

在这种情况下text = "Time to the t oast toastt oastt oasttoas ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast ttoasttoast toastt oasttoa sttoastto astto ast oasttoasttoasttoa sttoasttoast toastt oastto asttoastto asttoast toastt oast."

这只是一个例子

如您所见,通知 api 将其从中间剪掉并添加了三个点:

所以我的问题是,我可以让通知显示完整的消息而不是在中间剪掉吗?

我阅读了一些教程,发现有一个东西叫 expandedMessage ,但它没有出现在 API 文档中,我也没有成功使用它。

【问题讨论】:

  • 除了使用画布创建图像然后将其添加到rich notification之外,可能没有其他办法
  • @wOxxOm 好的,谢谢您的建议。让我们看看也许有人知道这是否可能。我已经阅读了一些教程,我看到有一个名为 expandMessage 的东西,但它没有出现在 API 文档中,我也没有成功使用它。

标签: google-chrome google-chrome-extension notifications rich-notifications


【解决方案1】:

您已经在使用扩展通知,并且行数是 hardcoded to 5 加上 Chromium/Chrome 源代码中的 first title line。正如您在链接代码中看到的那样,其他类型的文本通知可能会占用更少的行数。这就是为什么您只能看到 5+1=6 行。

克服限制的唯一方法是使用Canvas API 创建图像,绘制文本并将图像传递给chrome.notifications.create

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 2011-03-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多