Android InboxStyle Notification As Deep As Possible

InboxStyle notification is one of the notification styles provided by Android officially. In expand state, there are several more lines for displaying more information to user than that in its collapsed state. Unlike BigTextStyle
notification, each line is fixed to be a single line and content is truncated at the end when it is too long. Sample use case is adding snippets from incoming emails.

In InboxSytle
notification, there are 3 properties that can be configured. They are BigContentTitle
, SummaryText
and line
. They can all be styled by either limited HTML
tags or Spannables.
During my study about InboxStyle
, I unexpectedly find an Android documentation issue, which I have submitted to Google Issue Tracker, and will include it at the later part of this article. Let’s start!
All-in-one codes
1. BigContentTitle (CharSequence)

This BigContentTitle
is only shown when the BigText notification is expanded. It is a replacement of the contentTitle
which is set at the Notification builder (See the line 27 of the above sample code).
2. SummaryText (CharSequence)

This is a supplementary text shown in between the app name and the time (when) property of notification.
Bear in mind that this
summaryText
is overridden by thesubText
of theNotificationBuilder
. See the line 31 of the sample code shown above.
3. Line

Each line is represented by an individual TextView
and is fixed to be in single line. Text is truncated at the end when it is too long.
There is a discrepancy on the limit of line stated at different official documentation pages. This official page states the limit is 6 while the another one states it is 5. So which one is correct?


I was confused with these documentations when I was studying about InboxStyle
. Therefore, I decided to read through the InboxStyle
open source code and finally find out a mysterious answer — Max number of line is actually 7!

Starting from the line 7879, it is the makeBigContentView
function which is called to construct a view for the notification expanded state. In line 7884, the rowIds
array is constructed by a set of 7 view ids and each id points to a TextView
. At this moment, I am curious whether the maximum number of line is 7. After running the following codes, the 8th line is not shown and it verifies my suspicion.

So, can we say that the maximum number of line is “always” 7? No! Let’s take a look at the line 7898. The maximum number of line has to be reduced by 1 in order to release spaces for displaying a row of action button.

See below codes:

Is there any even more undocumented situation the maximum number of line is not either 6 or 7? Yes and it is the number of remote input history added. See the codes from line 7901 to 7922.:



These codes mean the maximum number of row would be reduced when there are more than 2 remote input histories. Moreover, there can only be at most 3 remote input histories to be shown at the same time.
Below are the codes for verification and screenshots of results:



To conclude, the max number of line to be shown depends on both the existence of action button and the number of remote histories shown. This documentation issue has been submitted to Google Issue Tracker since I wrote this article in 2020. See below table for a short summary:

Text styling


All texts in Notification can be styled manually by HTML tag, which is suggested officially at the official documentation. Here is an example:
However, beyond the suggested method, the texts can also be styled with Spanned
since all the functions for setting texts accept CharSequence
as a parameter. Here is an example:
To understand more about styling notification, please refer to the following article:
Want to know more about Android Notification:
1. Custom Notification
2. Android Notification All-In-One
3. BigTextSytle Notification
4. BigPictureStyle Notification
Summary
InboxStyle
notification is used for adding multiple short summary lines. Sample use case is the email notification.BigContentTitle
,summaryText
andline
are customisable properties inInboxStyle
notification. They are all simpleTextView
for displaying single line information.- The maximum number of
line
shown inInboxStyle
notification is wrongly documented in the official websites and actually depends on the existence of action button and the number of remote histories shown. It ranges from 3 to 7. - All text in notification can be styled by either HTML tag and
Spanned
.
Reference
- Android Notification open source code
2. Official documentation of how to create expandable notification
3. Inbox style official documentation
You are welcome to follow me at Twitter@myrick_chow for more information and articles. Thank you for reading this article. Have a nice day! 😄