There is no standard, official way to do this in Android.
Looks like they've piggybacked on the "accessibility" API, intercepting status bar notifications and trying to guess what they represent.
This approach just does not work right all the time. I mean, check Google Play comments for their app - multiple complaints about counters being wrong.
On my part, I have "unread counter" integration with Apex Launcher, Nova Launcher (Tesla Unread), Samsung TouchWiz, Sony launchers, and the counter's actual value is "pushed" directly and is therefore accurate.
If those guys want to integrate properly, well, I'll support that.
---
PS - links -- yes, spam protection... sorry about the inconvenience, but everyone here already has a Prada watch, right?