android – BigTextStyle通知的最大大小是多少

android – BigTextStyle通知的最大大小是多少,第1张

概述我有一个与 Android Wear集成的消息传递应用程序.与环聊类似,在Android Wear智能手表中选择通知时,您可以滑动到显示与所选消息对应的对话的第二张卡.我使用BigTextStyle通知实现它,但我需要知道BigTextStyle支持的最大字符数,这样我就可以在对话太大而无法完全适应时正确修剪对话.我在文档上找不到这个信息. 经过一些调查,max chars大约是5000,至少在A 我有一个与 Android Wear集成的消息传递应用程序.与环聊类似,在AndroID Wear智能手表中选择通知时,您可以滑动到显示与所选消息对应的对话的第二张卡.我使用BigTextStyle通知实现它,但我需要知道BigTextStyle支持的最大字符数,这样我就可以在对话太大而无法完全适应时正确修剪对话.我在文档上找不到这个信息.

经过一些调查,max chars大约是5000,至少在AndroID Wear模拟器中是这样.因此,我可以这样做:

// scroll to the bottom of the notification cardNotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender().setStartScrollBottom(true);// get conversation messages in a big single textCharSequence text = getConversationText();// trim text to its last 5000 charsint start = Math.max(0,text.length() - 5000);text = text.subSequence(start,text.length());// set text into the big text styleNotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle().bigText(text);// build notificationNotification notification = new NotificationCompat.Builder(context).setStyle(style).extend(extender).build();

有谁知道适合BigTextStyle通知的确切字符数?它是否在不同设备之间变化?

解决方法 简答
限制为5120个字符(5KB),但您无需限制邮件.这是在构建器上为您完成的.

详细解答

在您的代码中,您使用的是内部使用NotificationCompat.Builder的NotificationCompat.BigTextStyle.

当你调用setBigContentTitle时会发生这种情况

/**     * OverrIDes ContentTitle in the big form of the template.     * This defaults to the value passed to setContentTitle().     */    public BigTextStyle setBigContentTitle(CharSequence Title) {        mBigContentTitle = Builder.limitCharSequenceLength(Title);        return this;    }

功能limitCharSequenceLength执行此 *** 作

protected static CharSequence limitCharSequenceLength(CharSequence cs) {        if (cs == null) return cs;        if (cs.length() > MAX_CHARSEQUENCE_LENGTH) {            cs = cs.subSequence(0,MAX_CHARSEQUENCE_LENGTH);        }        return cs;    }

如果我们检查常量声明,我们发现了这一点

/**     * Maximum length of CharSequences accepted by Builder and frIEnds.     *     * <p>     * AvoIDs spamming the system with overly large strings such as full e-mails.     */    private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024;
总结

以上是内存溢出为你收集整理的android – BigTextStyle通知的最大大小是多少全部内容,希望文章能够帮你解决android – BigTextStyle通知的最大大小是多少所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1138973.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存