Read mobile phone contacts by PAGE

Source: Internet
Author: User

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 ;}
   
  
 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.