Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation("com.github.blainepwnz:AndroidContacts:1.14.0")
}
The minimum API level supported by this library is API 15. Library is not handling 23+ API permission.
Need to add permission to read contacts in manifest.
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
- Get all contacts from android device
- Get specific data from contacts
- Querying inside contacts
- Save new contacts
- Delete contacts
- Managing blocked contacts
- Phones
- Emails
- Addresses
- Groups
- Websites
- Nickname
- Note
- SIP
- Name
- Events
- Relations
- Photo
- Instant Messenger Addresses
- Lookup key
- Is favorite
Easiest way to get all data by one time:
new ContactsGetterBuilder(ctx)
.allFields()
.buildList();
Example: query that gets all contacts with photo and containing sequence "abc" in name.
new ContactsGetterBuilder(ctx)
.onlyWithPhotos()
.addField(FieldType.EMAILS, FieldType.ADDRESS)
.withNameLike("abc");
ContactData data = ContactDataFactory.createEmpty();
...Fill it with data
// id of newly created contact
int id = new ContactsSaverBuilder(context)
.saveContact(data);
val contactData = /* get contact data from somewhere */
val deleter = ContactsDeleter(context)
//usual delete with no need of callbacks
deleter.deleteContact(contactData)
//full range of callbacks, implement any you need
deleter.deleteContact(contactData) {
onCompleted { }
onFailure { }
onResult { }
doFinally { }
}