Gmail Android App Getting New Developer FeaturesBy: Zach Walton - April 4, 2012
I thought the Gmail Android app was pretty fantastic, but it’s never good enough for Google. Developers now have new tools at their disposal to implement a public ContentProvider “that you can use to retrieve label data.” This tool provides access to up-to-date unread counts for “specific accounts’ inboxes and labels.”
This new feature is contained inside of the Gmail Public Labels API. If you want to use it, the Gmail app needs to be at Android version 2.3.6 or higher on Froyo or Gingerbread; 4.0.5 or higher on Honeycomb and Ice Cream Sandwich.
To get started, you’re going to need a valid Gmail account to build the query for per-label information. You can obtain this through the AccountManager code which can be seen below:
After completing that step, use a ContentProvider URI to query against. Google has created a support class called GmailContact.java to help you in constructing the URI. This allows you to access any label within Gmail including priority inbox, starred, chats, sent, drafts, all mail, spam and trash.
Finally, developers can obtain a Cursor with information on all the labels. You can do this through either a query against the URI or use a CursorLoader. Google also cautions against identifying labels with GmailContract.Labels.NAME, saying that the NAME value can vary by locale. Instead, you should use GmailContract.Labels.CANONICAL_NAME. If you choose the CursorLoader route, Google says it will keep the “label counts up to date as they change over time.”
If you want to see the new API in action, Google has created a sample app that uses it. You can check it out here. Become educated and make Gmail delivery even better with this API.