[go: up one dir, main page]

Skip to content

KaranMavadhiya/Android_Contact-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android Contact-loader + AsyncTaskLoader

Android Permission

  • Add permission to your app/src/main/AndroidManifest.xml file
    <uses-permission android:name="android.permission.READ_CONTACTS" />

Retrieving a Cursor of Contacts

/* creating the projection which indicates what all data we want from our contacts database */
String[] projection = {
      ContactsContract.CommonDataKinds.Phone._ID,
      ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
      ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
      ContactsContract.CommonDataKinds.Phone.NUMBER,
      ContactsContract.CommonDataKinds.Email.ADDRESS,
      ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI
 };

Cursor contact_cursor = getContext().getContentResolver().query(
        ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
        null,
        null,
        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");

AsyncTaskLoader

  • loadInBackground
public class ContactLoader extends AsyncTaskLoader<List<Contact>> {

    public ContactLoader(Context context) {
        super(context);
    }

    @Override
    public List<Contact> loadInBackground() {
    ...
    
    }
  }
}

Referance

https://developer.android.com/training/contacts-provider/retrieve-names.html

https://developer.android.com/reference/android/content/AsyncTaskLoader.html

Releases

No releases published

Packages

No packages published

Languages