Extract all the contacts from android 'Contacts' application by using simple easy-to-use apis. It helps to remove the overhead of querying contact content provider.
Add permission in AndriodManifest.xml:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
Add this to your module's build.gradle
Gradle
dependencies {
...
implementation 'com.coderconsole.cextracter:contact-extractor:1.0.0'
}
Maven
<dependency>
<groupId>com.coderconsole.cextracter</groupId>
<artifactId>contact-extractor</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
Ivy
<dependency org='com.coderconsole.cextracter' name='contact-extractor' rev='1.0.0'>
<artifact name='contact-extractor' ext='pom' ></artifact>
</dependency>
Extract all the contacts from android 'Contacts' application by using simple easy-to-use apis. It helps to remove the overhead of querying contact content provider.
Name | Phone |
---|---|
CQuery cQuery = CQuery.getInstance(getActivity());
cQuery.filter(ICFilter.ONLY_PHONE);
cQuery.build(new IContact() {
@Override
public void onContactSuccess(List<CList> cList) {
if (cList != null && cList.size() > 0) {
CPhone cPhone = cList.getcPhone();
HashSet<String> home = cPhone.getHome();
HashSet<String> work = cPhone.getWork();
HashSet<String> mobile = cPhone.getMobile();
HashSet<String> other = cPhone.getOther();
}
}
@Override
public void onContactError(Throwable throwable) {
}
});
CQuery cQuery = CQuery.getInstance(getActivity());
cQuery.filter(ICFilter.ONLY_EMAIL);
cQuery.build(new IContact() {
@Override
public void onContactSuccess(List<CList> cList) {
if (cList != null && cList.size() > 0) {
CEmail cEmail = cList.getcEmail();
HashSet<String> home = cEmail.getHome();
HashSet<String> work = cEmail.getWork();
HashSet<String> mobile = cEmail.getMobile();
HashSet<String> other = cEmail.getOther();
}
}
@Override
public void onContactError(Throwable throwable) {
}
});
Extract all the Account - It name and its type e.g name - nitiwari.dev@gmail.com/ type - com.google.com
CQuery cQuery = CQuery.getInstance(getActivity());
cQuery.filter(ICFilter.ONLY_ACCOUNT);
cQuery.build(new IContact() {
@Override
public void onContactSuccess(List<CList> cList) {
if (cList != null && cList.size() > 0) {
CAccount cAccount = cList.getcAccount();
}
}
@Override
public void onContactError(Throwable throwable) {
}
});
Bingo Thats it !!!. Just change filter types and get the contact information accordingly.
Please do follows us on TWITTER and check out BLOG. #codingIsAnArt
Copyright (C) 2021 Nitesh Tiwari.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.