A (175)

(Tuis.) #1
CHAPTER 14: Android Content Providers: Providing Data to Applications 537

As you can see in Figure 1 4-2 8 , once you type the ContactsContract.Contacts (database.table)
reference in the .query( ) method parameter list, and then press the period key, a list of possible URIs
will then appear. Find the CONTENT_URI option and select it by double-clicking it to insert that into
your method call parameter. This will create the first ContactsContract.Contacts.CONTENT_URI
parameter for your method parameter list.


As you can see in Figure 14-29, you will need to mouse over the error highlighting under the Cursor
object, and choose the Import ‘Cursor’ (android.database) to import the Cursor class for use. Also
notice that the four parameter options for the getContentResolver( ).query( ) method call have been
named for you, and are also error underlined. This is to show you that there needs to be some valid
data in these in order for the method call to be valid, even if this is a “null” (which will serve as an
unused parameter indicator) data value.


Figure 14-29. Import the Cursor class; the projection, selection, selectionArgs, and sortOrder parameters


Since this chapter does not cover advanced SQL database concepts, such as projection, selection
arguments, and sorting orders, you are going to be using null values in these optional database
query parameters, as can be seen in the completed and error-free (but not warning-free) line of code
seen in Figure 14-30. If you mouse over the warning, you will see the standard “The value of the
local variable rulerCursor is not used” warning. Since you will be using the rulerCursor Cursor
object in the next line of code, ignore this warning for now. It is now time to create a do-while loop
construct, which will read through the now loaded ContentResolver.

Free download pdf