Pro Android with Kotlin


CHAPTER 6: Content Providers


Download 5.42 Mb.
Pdf ko'rish
bet81/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   77   78   79   80   81   82   83   84   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

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



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   77   78   79   80   81   82   83   84   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling