Add people metadata to notifications to influence notification ranking and priority mode
Pro-tip by +Ian Lake
Android notifications always try to order notifications by importance.
For a long time this was determined only by the notification’s priority and timestamp. With Android 5.0, a number of new metadata fields were added that influence ranking decisions. One of the most important of those is the option to associate people
with the notification, via addPerson()
addPerson() takes a URI in one of three forms:
- a CONTENT_LOOKUP_URI
) or the “permanent” link to an individual contact already in the user’s Contacts content provider
- a tel:
schema for phone numbers, which will use ContactsContract.PhoneLookup (http://goo.gl/K6C36e
) to find the associated user
- a mailto:
schema for email addresses
This search results in one of three outcomes for each notification: no match found, a match found, or a starred contact found
. Notifications from starred contacts are deemed the most important, while any
match is deemed a higher priority than no contact at all. This means that adding people information may break a tie between similar notifications
, favoring the notification that includes people in the user’s contacts.
If you’ve used priority mode to filter out notifications to only the essential, you may have noticed that one of the options there is to only receive calls or messages from starred contacts
- this uses the same people metadata
to determine whether a notification should interrupt a user. Adding this information can be key to ensuring that user’s expectations in priority mode are honored.
You don’t need to build your own contacts provider (http://goo.gl/4lwvU4
) or even have the Contacts permission to take advantage of addPerson() - adding what information you have in the form of email addresses or phone numbers can be enough to improve the user’s notification experience, leveraging the contacts they already have on their device.