中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android分頁(yè)查詢(xún)獲取系統(tǒng)聯(lián)系人信息

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線(xiàn)!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
  
import java.util.ArrayList;  
import java.util.List;  
  
  
import android.R.integer;  
import android.content.Context;  
import android.database.Cursor;  
import android.net.Uri;  
  
import android.provider.ContactsContract;  
  
  
  
import com.example.yqqmobilesafe.domain.ContactInfo;  
  
public class ContactInfoProvider {  
    private Context mContext;  
    public ContactInfoProvider(Context context) {  
        mContext=context;  
          
    }  
    /** 
     * 獲取系統(tǒng)聯(lián)系人信息 
     * @return 
     */  
    public  List<ContactInfo> getSystemContactInfos(){  
        List<ContactInfo> infos=new ArrayList<ContactInfo>();  
          
        // 使用ContentResolver查找聯(lián)系人數(shù)據(jù)  
        Cursor cursor = mContext.getContentResolver().query(  
            ContactsContract.Contacts.CONTENT_URI, null, null,  
            null, null);  
          
        // 遍歷查詢(xún)結(jié)果,獲取系統(tǒng)中所有聯(lián)系人  
        while (cursor.moveToNext())  
        {  
            ContactInfo info=new ContactInfo();  
            // 獲取聯(lián)系人ID  
            String contactId = cursor.getString(cursor  
                .getColumnIndex(ContactsContract.Contacts._ID));  
            // 獲取聯(lián)系人的名字  
            String name = cursor.getString(cursor.getColumnIndex(  
                ContactsContract.Contacts.DISPLAY_NAME));  
            info.setContactName(name);  
              
            // 使用ContentResolver查找聯(lián)系人的電話(huà)號(hào)碼  
            Cursor phones = mContext.getContentResolver().query(  
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,  
                null,  
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID  
                    + " = " + contactId, null, null);  
              
            // 遍歷查詢(xún)結(jié)果,獲取該聯(lián)系人的多個(gè)電話(huà)號(hào)碼  
            while (phones.moveToNext())  
            {  
                // 獲取查詢(xún)結(jié)果中電話(huà)號(hào)碼列中數(shù)據(jù)。  
                String phoneNumber = phones.getString(phones  
                    .getColumnIndex(ContactsContract  
                    .CommonDataKinds.Phone.NUMBER));  
                info.setPhoneNumber(phoneNumber);  
            }  
            phones.close();  
              
            infos.add(info);  
            info=null;  
        }  
        cursor.close();  
          
        return infos;  
          
    }  
      
    /** 
     * 分頁(yè)查詢(xún)系統(tǒng)聯(lián)系人信息 
     * @param pageSize 每頁(yè)最大的數(shù)目 
     * @param currentOffset 當(dāng)前的偏移量 
     * @return 
     */  
    public List<ContactInfo> getContactsByPage(int pageSize,int currentOffset) {  
          
        List<ContactInfo> infos=new ArrayList<ContactInfo>();  
                Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;   
                String[] projection = { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,  
                                        ContactsContract.CommonDataKinds.Phone.DATA1, "sort_key"};  
                Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, "sort_key COLLATE LOCALIZED asc limit " + pageSize + " offset " + currentOffset);  
                if (cursor != null) {  
                      
                    while (cursor.moveToNext()) {  
                          
                        ContactInfo info=new ContactInfo();  
                        String contactName = cursor.getString(0);  
                        String phoneNumber = cursor.getString(1);  
                        info.setContactName(contactName);  
                        info.setPhoneNumber(phoneNumber);  
                        infos.add(info);  
                        info=null;  
                    }  
                    cursor.close();  
                  
              
    }  
                return infos;  
    }  
      
    /** 
     * 獲得系統(tǒng)聯(lián)系人的所有記錄數(shù)目 
     * @return 
     */  
    public int getAllCounts(){  
        int num=0;  
        // 使用ContentResolver查找聯(lián)系人數(shù)據(jù)  
                Cursor cursor = mContext.getContentResolver().query(  
                    ContactsContract.Contacts.CONTENT_URI, null, null,  
                    null, null);  
                  
                // 遍歷查詢(xún)結(jié)果,獲取系統(tǒng)中所有聯(lián)系人  
                while (cursor.moveToNext())  
                {  
                    num++;  
                }  
                cursor.close();  
      
  
        return num;  
    }  
      
  
}  

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀(guān)點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Android下獲取SD卡的狀態(tài)并寫(xiě)入文件到SD卡

下一篇: 自動(dòng)監(jiān)控url是否可用,如不可用則重啟應(yīng)用,并做相應(yīng)的報(bào)警策略