In this blog post we will be discussing an Android view type called a QuickContactBadge. A QuickContactBadge is an Android widget that shows an image and, when clicked, provides the user with a collection of different ways to communicate with that contact based on what contact information you have available for that contact. For instance, if only a contact's phone number is listed, your only option that pops up may be to call that person. However, if you have that contact's phone number, email address, and IM handle, then options for interacting with that person on all those platforms will be listed. Creating a QuickContactBadge is done in the layout XML like with any view type:
In order for there to be something for the user to click on, the QuickContactBadge needs to have an image associated with it. Whatever image you choose will need to be defined in the "android:src" parameter, as shown above. This image can be changed on the fly based on the selected contact if you so choose, and that will be explained later. First things first, though, is to define this QuickContactBadge in your code, as so:
This will define your QuickContactBadge and set its type as a Large QuickContactBadge, which includes an image of the contact if present like this:
Next you need to select the contact you want to associate with your QuickContactBadge. This can be done in one of two ways. First, if you only know the phone number or email address of your contact, you can use the functions "assignContactFromEmail(String emailAddress, boolean lazyLookup)" or "assignContactFromPhone(String phoneNumber, boolean lazyLookup)". For example, if you only know a contact's email address is firstname.lastname@example.org, you can assign the contact by email usingmyQuickContactBadge.assignContactFromEmail("email@example.com", true). The second way would be to set the associated contact using a Uri. This Uri can be queried for in a number of ways from Android Contact's content provider, but in this example we are going to launch a contact picker intent and select the contact manually.
After selected a contact and using the returned Uri to populate the QuickContactBadge, you should now have a functioning QuickContactBadge that displays that contact's image, and when pressed will provide the user with options for ways to contact that contact based on the information stored for that contact. An example of your completed QuickContactBadge is shown below
--by James Catalano
Subscribe to our Cius Developer Blog RSS feed to get the latest info and sample code.