Sunday, 15 March 2015

android read name and phone n umbers from the addressbok

private void getCont() {

// TODO Auto-generated method stub
        ArrayList<String> contacts = new ArrayList<String>();

        Cursor c = getContentResolver().query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                null, null, null);
        while (c.moveToNext()) {

            String contactName = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String phNumber = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

            contacts.add(contactName + ":" + phNumber);
           
            Log.d("contactName", ""+contactName);
            Log.d("phNumber", ""+phNumber);

        }
        c.close();
}