7

안녕하세요 기본 연락처 의도에서 연락처를 선택하고 싶습니다. 나는 그것을하기 위해 몇 가지 방법을 시도했다. 아래 코드를 찾으십시오. 이 모든 코드의 문제점은 사용자가 연락처를 선택해야하는 몇 가지 옵션으로 하나의 중간 문서 화면을 열고 연락처 북을 열기 때문입니다.연락처 선택 도구에서 직접 연락처 선택

private void openContactIntent() { 
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, ContactsContract.Contacts.CONTENT_URI); 
    intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); 
    startActivityForResult(intent, REQ_CONTACT_DIRECTORY); 
} 

은 또한 내가 중간 화면으로 참조하면 enter image description here

+0

'의도 의도 아래로

Intent i=new Intent(Intent.ACTION_PICK); i.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); startActivityForResult(i, SELECT_PHONE_NUMBER); 

onActivityResult GET 전화 번호, 코드 아래 사용하여 중간 선택기 화면을 없애있어 = 새로운 의도 (Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI) ; startActivityForResult (인 텐트, PICK_CONTACT);'나를 위해 일하고있다! –

+0

모든 OS와 관련이 있습니까? Android N에서 코드를 실행하고 있습니다. 나를 위해 작동하지 않습니다. 나는 어떤 허가도 추가하지 않았다. –

+0

나는 Android N도 실행 중입니다. –

답변

0
Try This link may to be help you 

http://stackandroid.com/tutorial/contact-picker-using-intent-android-tutorial/

이다

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); 
startActivityForResult(intent, PICK_CONTACT); 

Intent intent = new Intent(Intent.ACTION_PICK); 
intent.setType(ContactsContract.Contacts.CONTENT_TYPE); 
startActivityForResult(intent, PICK_CONTACT); 

시도

+0

휴대폰에 첨부 된 스크린 샷과 같은 사이드 메뉴 화면을 열어 내부에 연락처가 표시되지 않습니다. –

0

이 나를 위해 작동합니다

Intent it= new Intent(Intent.ACTION_PICK, 
    ContactsContract.Contacts.CONTENT_URI); 
startActivityForResult(it, requestCode); 
2

접촉 선택하기 위해 아래 코드를 사용해보십시오 :

의도 contactPickerIntent = 새로운 의도 (Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI을); startActivityForResult (contactPickerIntent, RESULT_PICK_CONTACT); 다음과 같이

당신은하여 onActivityResult에서 필요한 정보를 가져올 수 있습니다 :

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (resultCode == RESULT_OK) { 
     switch (requestCode) { 
      case RESULT_PICK_CONTACT: 
        Cursor cursor = null; 
    try { 
     String phoneNo = null; 
     String name = null; 

     Uri uri = data.getData(); 
     cursor = getContentResolver().query(uri, null, null, null, null); 
     cursor.moveToFirst(); 
     int phoneIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); 
     int nameIndex =cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); 
     phoneNo = cursor.getString(phoneIndex); 
     name = cursor.getString(nameIndex); 

     Log.e("Name and Contact number is",name+","+phoneNo); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
       break; 
     } 
    } else { 
     Log.e("Failed", "Not able to pick contact"); 
    } 
} 
+0

이 솔루션은 나를 위해 일했습니다! –

+0

oH .. !! 멋지다 .. !! –

5

는 또한 같은 문제가 있었다. 마지막으로, 나는

if (requestCode == SELECT_PHONE_NUMBER && resultCode == RESULT_OK) { 
    // Get the URI and query the content provider for the phone number 
    Uri contactUri = data.getData(); 
    String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER}; 
    Cursor cursor = getContext().getContentResolver().query(contactUri, projection, 
     null, null, null); 

    // If the cursor returned is valid, get the phone number 
    if (cursor != null && cursor.moveToFirst()) { 
    int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); 
    String number = cursor.getString(numberIndex); 
    // Do something with the phone number 
    ... 
    } 

    cursor.close(); 
}