87
CHAPTER 6: Content Providers
ContactsContract.RawContacts:
A set of data describing a person.
ContactsContract.Contacts:
An aggregated view on a person, possibly related to several rows inside
the RawContacts table. Because of its aggregating nature, it is writable
only in parts.
There are more contract-related tables described as inner classes of ContactsContract.
Instead of explaining all the possible use cases for the contact’s content provider, to
get you started, we just present code to list the contents of the three main tables listed
previously, show what a single new contact writes there, and otherwise refer to the online
documentation of the ContactsContract class. To list the contents of the three tables, use
the following:
fun showTable(tbl:Uri) {
Log.e("LOG", "##################################")
Log.e("LOG", tbl.toString())
val cursor = contentResolver.query(
tbl, null, null, null, null)
cursor.moveToFirst()
while (!cursor.isAfterLast) {
Log.e("LOG", "New entry:")
for(name in cursor.columnNames) {
val v = cursor.getString(
cursor.getColumnIndex(name))
Log.e("LOG"," > " + name + " = " + v)
}
cursor.moveToNext()
}
}
...
showTable(ContactsContract.Contacts.CONTENT_URI)
showTable(ContactsContract.RawContacts.CONTENT_URI)
showTable(ContactsContract.Data.CONTENT_URI)
If you create a new contact using Android’s pre-installed Contacts app, inside the Contacts
view table you will find the following new entry (here only the important columns):
_id = 1
display_name_alt = Mayer, Hugo
sort_key_alt = Mayer, Hugo
has_phone_number = 1
contact_last_updated_timestamp = 1518451432615
display_name = Hugo Mayer
sort_key = Hugo Mayer
times_contacted = 0
name_raw_contact_id = 1
Do'stlaringiz bilan baham: |