2011-11-26 107 views

回答

2
private void getContactData() { 
     Cursor phoneCursor = null; 
     contactList = new HashMap<String,String>(); 

     try{ 
      // 주소록이 저장된 URI 
      Uri uContactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 

      // 주소록의 이름과 전화번호의 열 이름 
      String strProjection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME; 

      // 주소록을 얻기 위한 쿼리문을 날리고 커서를 리턴 
      phoneCursor = getContentResolver().query(uContactsUri, null, null, null, strProjection); 
      phoneCursor.moveToFirst(); 

      String name = ""; 
      String phoneNumber = ""; 

      // 주소록의 이름 
      int nameColumn = phoneCursor.getColumnIndex(Phone.DISPLAY_NAME); 
      // 주소록의 전화번호 
      int phoneColumn = phoneCursor.getColumnIndex(Phone.NUMBER); 

      while(!phoneCursor.isAfterLast()){ 
       name = phoneCursor.getString(nameColumn); 
       phoneNumber = phoneCursor.getString(phoneColumn); 

       // HashMap에 data 넣음 
       contactList.put(name, phoneNumber); 
       phoneCursor.moveToNext(); 
      } 
     } 
     catch(Exception e){ 
      Log.e("[SmsMain] getContactData", e.toString()); 
     } 
     finally{ 
      if(phoneCursor != null){ 
       phoneCursor.close(); 
       phoneCursor = null; 
      } 
     } 
    } 

這是獲取聯繫人數據庫的來源。

我解決了搜索。

+4

請用英語評論,它的不可讀性如何。 –

相關問題