Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet139/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   135   136   137   138   139   140   141   142   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

159
CHAPTER 8: APIs
ContactsContract.RawContacts.ACCOUNT_NAME,
accountName)
opList.add(op.build())
Next, still inside the method, we create a display name for the new row. This is a row inside 
the table StructuredName.
// Creates the display name for the new row
op = ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI)
// withValueBackReference will make sure the
// foreign key relations will be set
// correctly
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID,
firstOperationIndex)
// The data row's MIME type is StructuredName
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.
StructuredName.CONTENT_ITEM_TYPE)
// The row's display name is the name in the UI.
.withValue(ContactsContract.CommonDataKinds.
StructuredName.DISPLAY_NAME,
firstName + " " + lastName)
opList.add(op.build())
Likewise, we add the phone number and the e-mail address.
// The specified phone number
op = ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI)
// Fix foreign key relation
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID,
firstOperationIndex)
// Sets the data row's MIME type to Phone
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.
Phone.CONTENT_ITEM_TYPE)
// Phone number and type
.withValue(ContactsContract.CommonDataKinds.
Phone.NUMBER, phone)
.withValue(ContactsContract.CommonDataKinds.
Phone.TYPE,
android.provider.ContactsContract.
CommonDataKinds.Phone.TYPE_HOME)
opList.add(op.build())
// Inserts the email
op = ContentProviderOperation.newInsert(
ContactsContract.Data.CONTENT_URI)
// Fix the foreign key relation
.withValueBackReference(



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   135   136   137   138   139   140   141   142   ...   223




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