query Phone Contact List - Android Account

Android examples for Account:Contact

Description

query Phone Contact List

Demo Code


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.MediaStore;
import android.support.v4.content.CursorLoader;
import android.util.Log;

public class Main{
    private static final String[] PROJECTION_PHONE = { Data._ID,
            Phone.NUMBER, Phone.TYPE, Phone.LABEL };
    private static final String SELECTION_PHONE = Data.LOOKUP_KEY + "=?"
            + " AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE
            + "'";
    public static List<String> queryPhoneList(
            ContentResolver contentResolver, String lookupKey) {
        List<String> phoneList = new ArrayList<String>();
        Cursor phoneCursor = queryPhone(contentResolver, lookupKey);
        while (phoneCursor.moveToNext()) {
            phoneList.add(phoneCursor//from w w w .j  a  v  a2s. com
                    .getString(ContactDetailsIndexes.NUMBER_ADDRESS
                            .ordinal()));
        }
        phoneCursor.close();
        return phoneList;
    }
    public static Cursor queryPhone(ContentResolver contentResolver,
            String lookupKey) {
        String[] selectionArgs = { lookupKey };
        return contentResolver.query(Data.CONTENT_URI, PROJECTION_PHONE,
                SELECTION_PHONE, selectionArgs, null);
    }
}

Related Tutorials