How do I use delete APIs to delete custom data?

Android Contacts API Library written in Kotlin with Java interoperability. No more ContentProviders and cursors. Say goodbye to ContactsContract. Build your own contacts app!

How do I use delete APIs to delete custom data?

This library provides several APIs that supports deleting custom data.

  1. DataDelete
  2. Delete
  3. ProfileDelete
  4. Update
  5. ProfileUpdate

To help illustrate how custom data integrates with these update APIs, we’ll use the HandleName and Gender custom data.

For more info about custom data, read How do I integrate custom data?

Deleting custom data via Contacts/RawContacts

Custom data, just like regular data kinds, are attached to a RawContact. They follow the same rules as regular data kinds.

For more info, read How do I learn more about the API entities?

For example, you are able to delete existing handle names and the gender of an existing RawContact,

mutableRawContact.removeHandleName(contactsApi, handleName)
mutableRawContact.setGender(contactsApi, null)

There are also extensions that allow you to delete custom data of an existing RawContact via a Contact, which can be made up of one or more RawContacts,

mutableContact.removeHandleName(contactsApi, handleName)
mutableContact.setGender(contactsApi, null)

Once you have removed custom data, you can perform the update operation on the RawContact to commit your changes into the database using Update or ProfileUpdate.

You may also delete an entire Contact or RawContact using Delete or ProfileDelete in order delete all associated data.

Deleting set of custom data directly

All custom data are compatible with the DataDelete API, which allows you to delete sets of existing regular and custom data kinds.

For example, to delete a set of HandleNames and Genders,

val handleNames: List<MutableHandleName>
val genders: List<MutableGender>

val deleteResult = Contacts(this)
   .data(handleNames + genders)

For more info, read How do I delete existing sets of data?