GithubHelp home page GithubHelp logo

muhammadelkady25 / androidcontacts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blainepwnz/androidcontacts

0.0 1.0 0.0 238 KB

Easy to use library for contacts aggregation

License: MIT License

Java 100.00%

androidcontacts's Introduction

AndroidContacts


GitHub license Download

Gradle Dependency

Step 1. Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			jcenter()
    	}
	}

Step 2. Add the dependency

	dependencies {
		compile 'com.tomash:androidcontacts:1.10.0'
	}

Basic Usage

The minimum API level supported by this library is API 15.

Need to add permisson to read contacts in manifest.

<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
Basic usage
  1. Get all contacts from android device
  2. Get specific data from contacts
  3. Querying inside contacts
  4. Save new contacts

Type of fields you can get

  • Phones
  • Emails
  • Addresses
  • Groups
  • Websites
  • Nickname
  • Note
  • SIP
  • Name
  • Events
  • Relations
  • Photo
  • Instant Messenger Addresses
  • Lookup key

Easiest way to get all data by one time:

 new ContactsGetterBuilder(ctx)
            .allFields()
            .buildList();

Filter by contacts only with numbers

 new ContactsGetterBuilder(ctx)
          .onlyWithPhones()
		  .buildList();          

Querying

Library supports multi querying by contacts,plus you can implement your own filters.

For 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");

Get contact with specific phone number. firstOrNull returns only one Contact if found and null otherwise.

new ContactsGetterBuilder(ctx)
    .withPhone("123456789")
    .firstOrNull();   

Get contact by local contact id

ContactData contactData  = new ContactsGetterBuilder(ctx)
   .addField(FieldType.EMAILS,FieldType.ADDRESS,FieldType.NAME_DATA)
   .getById(123);

Saving new contacts

How to save contacts objects using library?

  1. Create ContactData object or use yours

    ContactData data = ContactDataFactory.createEmpty();
    
  2. Fill it with data

    data.setCompositeName("Name");
    List<Email> emailList  = new ArrayList<>();
    //creates email with custom label
    emailList.add(new Email("[email protected]","custom label"));
    //creates email with home label
    emailList.add(new Email(context,"[email protected]",Email.TYPE_HOME));
    //cretaes email with default label
    emailList.add(new Email(context,"[email protected]"));
    
  3. Save data to phone

    //this id is id of newly created contact
    int id =new ContactsSaverBuilder(context)
        .saveContact(data);
    

####Note To save list of contacts use:

    int[] id =new ContactsSaverBuilder(context)
        .saveContactsList(contactDataList);

Using custom Contact object

#####How to use library with your custom contact class?

  1. Inherit from ContactData
  2. Add empty constructor
  3. That's all!
public class MyAwesomeContactObject extends ContactData {
    private String mySuperField;

    //Important to add empty constructor
    public MyAwesomeContactObject() {
    }

    //getters , setters , any logic you wish
}
How to use it after?
List<MyAwesomeContactObject> objects  = new ContactsGetterBuilder(ctx)
    .onlyWithPhones()
    .onlyWithPhotos()
    .withEmailLike("@gmail.com")
    .buildList(MyAwesomeContactObject.class);

Whats new?

1.1.0

  • Added contacts saver
  • Fixed bugs for Android api<18
  • Covered contacts saver and getter with tests
  • Reworked WithLabel objects creation

1.0.6

  • Improved contacts getter performance

1.0.5

  • Added support of custom Contact objects
  • Added lookup key

androidcontacts's People

Contributors

blainepwnz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.