Read mobile phone contacts by PAGE
/*** Number of contacts on the mobile phone */public static int linkManCount =-1;/*** number of contacts displayed on each page */public static int pageCount = 20;
/*** Get the mobile phone contact and return ** @ param mContext * context object * @ param pageSize * Number of pages of data to be retrieved currently * @ return */public ArrayList
GetLinkMan (Context mContext, int pageSize) {ArrayList
LinkMans = new ArrayList
(); ContentResolver cr = mContext. getContentResolver (); // get the Cursor cursor Cursor = cr for the first entry in the phone book. query (ContactsContract. contacts. CONTENT_URI, null, null); // move the cursor linkManCount = cursor down. getCount (); if (cursor! = Null & (pageSize-1) * pageCount) <linkManCount) {cursor. moveToPosition (pageSize-1) * pageCount); int I = 0; while (cursor. moveToNext () {if (I <pageCount) {Cursor phone = null; String contact = null; try {// get the contact name int nameFieldColumnIndex = cursor. getColumnIndex (PhoneLookup. DISPLAY_NAME); contact = cursor. getString (nameFieldColumnIndex); // call String ContactId = cursor. getString (cursor. get ColumnIndex (ContactsContract. contacts. _ ID); phone = cr. query (ContactsContract. commonDataKinds. phone. CONTENT_URI, null, ContactsContract. commonDataKinds. phone. CONTACT_ID + = + ContactId, null, null);} catch (Exception e) {LogUtil. d (TAG. An error is returned when the cursor gets the phone !); Break;} LogUtil. d (TAG, Cursor phone + phone); if (phone! = Null) {while (phone. moveToNext () {String Number = phone. getString (phone. getColumnIndex (ContactsContract. commonDataKinds. phone. NUMBER); // string + = (contact +: + Number +); helperPoSort man = new helperPoSort (); man. setStr1 (contact); man. setStr2 (Number); LogUtil. d (TAG, contact +: + Number +); linkMans. add (man) ;}} I = I + 1 ;}else {break ;}} cursor. close (); return linkMans ;}