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(
Do'stlaringiz bilan baham: |