마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

자신의 전화번호부에서 전화번호 가져오기

0 추천
public class MainActivity extends Activity {
  
  String tag = null;
  ListView list;
   
   @Override
   public void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.activity_main);

    list = (ListView)findViewById(R.id.list_Contact);
    getList();
   
   }
   

   private void getList() {
    // TODO Auto-generated method stub
    
    // 주소록 URI
    Uri people = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    
    // 검색할 컬럼 정하기
          String[] projection = new String[] {
            ContactsContract.CommonDataKinds.Phone._ID,
            ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
            ContactsContract.CommonDataKinds.Phone.NUMBER
          };
          
          @SuppressWarnings("deprecation")
    Cursor cursor = managedQuery(people, projection, null, null, null);    // 전화번호부 가져오기 
    
    int end = cursor.getCount();    // 전화번호부의 갯수 세기
    Log.d(tag, "end = "+end);
  
    String[] name = new String[end]; // 전화번호부의 이름을 저장할 배열 선언
    String[] phone = new String[end];
    
    int count = 0; 
  
    if(cursor.moveToFirst()) 
    {
     // 컬럼명으로 컬럼 인덱스 찾기 
     int idIndex = cursor.getColumnIndex(Phone._ID);
     int nameIndex = cursor.getColumnIndex(Phone.DISPLAY_NAME);
     int phoneIndex = cursor.getColumnIndex(Phone.NUMBER);
     
  
     do 
     {
      // 요소값 얻기
      int id = cursor.getInt(idIndex);   
      name[count] = cursor.getString(nameIndex);
      phone[count] = cursor.getString(phoneIndex);
  
      // LogCat에 로그 남기기
      Log.d(tag, "id = " + id +", name["+count+"]=" + name[count]);
      count++;
      
      Log.d(tag, "id, count=" + id + "," + count +", 이름 =" + name[count] +", 번호=" +phone[count]);
      
     } while(cursor.moveToNext() || count > end);
    }  
    
   }  

 }

자신의 전화번호부로 이동해 거기에서 자신이 선택한 전화번호들을 가져오는 건데요

기본적으로 하나를 선택해서 지정된 곳에 가져오는 것 까지는 했는데

전화번호를 여러개 선택해서 가져오는 것을 할라 하는데 안되는데 뭐가 문제인지 좀 봐주세요

 

 

익명사용자 님이 2014년 5월 7일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...