Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.quiin:unifiedcontactpicker:1.0'
}
dependencies {
implementation("com.github.quiin:unifiedcontactpicker:1.0")
}
<dependency>
<groupId>com.github.quiin</groupId>
<artifactId>unifiedcontactpicker</artifactId>
<version>1.0</version>
</dependency>
libraryDependencies += "com.github.quiin" % "unifiedcontactpicker" % "1.0"
:dependencies [[com.github.quiin/unifiedcontactpicker "1.0"]]
This library unifies the user contacts in a compact and user intuitive way allowing the end-user to choose between the contact's available communication options (email/phone number) follows Material Design guidelines.
Although there is a standard way to call the contact list in Android, it does not always feel well-integrated in your app Android applications. UnifiedContactPicker is an Android library which allows you to easily integrate contact picking workflow into your application with minimal effort
This library is no longer in active development. However, pull requests for new features or bugfixes are always welcomed and will be attended.
In order to use the library, add the following line to your root gradle file:
<pre> <code> repositories { jcenter() maven { url "https://jitpack.io" } ... } </code> </pre>As well as this line in your project build.gradle file
<pre> <code> dependencies { compile 'com.github.quiin:unifiedContactPicker:{LATEST_VERSION}' ... } </code> </pre>To use UnifiedContactPicker in your app simply follow this 3 simple steps:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
// Your Activity or Fragment
public void launchContactPicker(View view) {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
if(permissionCheck == PackageManager.PERMISSION_GRANTED){
Intent contactPicker = new Intent(this, ContactPickerActivity.class);
startActivityForResult(contactPicker, CONTACT_PICKER_REQUEST);
}else{
ActivityCompat.requestPermissions(this,
new String[] {Manifest.permission.READ_CONTACTS},
READ_CONTACT_REQUEST);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode){
case CONTACT_PICKER_REQUEST:
if(resultCode == RESULT_OK){
TreeSet<SimpleContact> selectedContacts = (TreeSet<SimpleContact>)data.getSerializableExtra(ContactPickerActivity.CP_SELECTED_CONTACTS);
for (SimpleContact selectedContact : selectedContacts)
Log.e("Selected", selectedContact.toString());
}else
Toast.makeText(this, "No contacts selected", Toast.LENGTH_LONG).show();
break;
default:
super.onActivityResult(requestCode,resultCode,data);
}
}
Contacts are returned in a TreeSet of SimpleContact; each SimpleContact object ha the following accessible properties:
:warning: IMPORTANT
As of SDK 23 (Android 6) developers are requested to explicitly ask for permissions at runtime. So please be sure to request for contact reading permissions using the previous code or any other means you prefer.
The following UI views can be customized:
| UI component | Intent extra | Expected value | Type | Sugestion | |:----------------------:|:-------------------------:|:--------------:|:-------:|:---------:| | FAB color | CP_EXTRA_FAB_COLOR | hexColor | String | - | | Selection color | CP_EXTRA_SELECTION_COLOR | hexColor | String | - | | Selection Drawable |CP_EXTRA_SELECTION_DRAWABLE| Image | byte [] |use PickerUtils.sendDrawable()| | Fab drawable | CP_EXTRA_FAB_DRAWABLE | Image | byte [] |use PickerUtils.sendDrawable()| | Chips | CP_EXTRA_SHOW_CHIPS | boolean | boolean | - |
Aditionally, you can customize the contact query parameters used to extract the user's contacts adding the following extras to the intent
| Extra | Type | |:---------------------------------:|:---------:| |CP_EXTRA_PROJECTION | String [] | |CP_EXTRA_SELECTION | String | |CP_EXTRA_SELECTION_ARGS | String [] | |CP_EXTRA_HAS_CUSTOM_SELECTION_ARGS | boolean | |CP_EXTRA_SORT_BY | String |
public void launchContactPicker(View view) {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
if(permissionCheck == PackageManager.PERMISSION_GRANTED){
Intent contactPicker = new Intent(this, ContactPickerActivity.class);
//Don't show Chips
contactPicker.putExtra(ContactPickerActivity.CP_EXTRA_SHOW_CHIPS, false);
//Customize Floating action button color
contactPicker.putExtra(ContactPickerActivity.CP_EXTRA_FAB_COLOR, "#FFF722");
//Customize Selection drawable
contactPicker.putExtra(ContactPickerActivity.CP_EXTRA_SELECTION_DRAWABLE, PickerUtils.sendDrawable(getResources(),R.drawable.my_drawable));
startActivityForResult(contactPicker, CONTACT_PICKER_REQUEST);
}else{
ActivityCompat.requestPermissions(this,
new String[] {Manifest.permission.READ_CONTACTS},
READ_CONTACT_REQUEST);
}
}
Default projection columns:
Default selection query:
"(" + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=?)"