Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 15  Implicit Intents


Run CriminalIntent and press the CHOOSE SUSPECT button. You should see a list of contacts
(Figure 15.5).


Figure 15.5  A list of possible suspects


If you have a different contacts app installed, your screen will look different. Again, this is one of the
benefits of implicit intents. You do not have to know the name of the contacts application to use it from
your app. Users can install whatever app they like best, and the OS will find and launch it.


Getting the data from the contact list


Now you need to get a result back from the contacts application. Contacts information is shared
by many applications, so Android provides an in-depth API for working with contacts information
through a ContentProvider. Instances of this class wrap databases and make it available to other
applications. You can access a ContentProvider through a ContentResolver.


Because you started the activity for a result with ACTION_PICK, you will receive an intent via
onActivityResult(...). This intent includes a data URI. The URI is a locator that points at the single
contact the user picked.


In CrimeFragment.java, retrieve a contact’s name from the contacts application in your
onActivityResult(...) implementation in CrimeFragment.

Free download pdf