This application demonstrates the "MobileContactsLib", The library uses the "ContentResolver", it is a well structured, fast, easy to use and easy to modify library for getting contacts from the mobile. This library requires minimum SDK 15.
Images from the app:
The demo app for this library is available on Google Play:
In the app manifest file add this permission:
<uses-permission android:name="android.permission.READ_CONTACTS" />
In the app build.gradle add the following:
a. Add JitPack repository at the end of repositories
repositories {
maven { url 'https://jitpack.io' }
}
b. Then add this dependency
dependencies {
compile 'com.github.Jagerfield:Mobile-Contacts-Library:v1.7'
}
There are two ways to implement this library, the first method is to directly implement it on the main-thread. The library is fast and I didn't ntice any delays.
- After instaling the library, declare and instantiate an object of type "ImportContacts" class with "context" as an argument.
- Call the getContacts() method to get all the contacts.
/**
* Declare and instantiate an object of the "ImportContacts" class
*/
ImportContacts importContacts = new ImportContacts(context);
/**
* Fetch mobile contacts list
*/
ArrayList<Contact> listItem = importContacts.getContacts();
From version 1.7, you can fetch contacts through an Async call.
new ImportContactsAsync(activity, new ImportContactsAsync.ICallback()
{
@Override
public void mobileContacts(ArrayList<Contact> contactList)
{
//Your code here
}
}).execute();
1. Name:
a. Displaydname
b. Firstname
c. Lastname
2. Nickname:
a. Nickname
b. Nicknametype
3. Number:
a. Number
b. Normalizednumber
c. Numbertype
4. Email:
a. Email
b. Emaillabel
c. Emailtype
5. Website:
a. Website
6. Event:
a. Eventstartdate
b. Eventlabel
c. Eventtype
7. Note:
a. Note
8. Address:
a. Address
b. Addresstype
This is a general diagram of the library's architectural design, and it only includes the numbers elements for clarity.
A version of this library is used in Data & Contacts Sharing Mgr
The Mobile Contact Library uses the Android Utilities Library to manage permissions:
This app sample will request the follwoing permission below which require user approval and is used for demonstration purposes only. No data is shared or used outside this app.
- android.permission.READ_CONTACTS