7

Merhaba Temas iletişim rehberden bir kişi seçmek istiyorum. Bunu yapmanın birkaç yolunu denedim. Lütfen aşağıdaki kodu bulun. Tüm bu kodla ilgili problem, kullanıcının bir kişi ara ekranını açmak zorunda olduğu birkaç seçenekle bir ara doküman ekranı açmasıdır.Temas toplayıcısından doğrudan kişi ile iletişim kurun.

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

Ben de ne bir ara ekran olarak bkz enter image description here

+0

'Niyet niyet aşağıdaki gibi

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

onActivityResult olsun telefonu numarası olarak kodunun altına kullanarak ara toplayıcı ekranın kurtuldum = new Niyet (Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI) ; startActivityForResult (niyet, PICK_CONTACT); 'Bu benim için çalışıyor! –

+0

Herhangi bir işletim sistemi ile ilişkili midir? Android N'de kod çalıştırıyorum ve benim için çalışmıyor. Herhangi bir izin eklemedim. –

+0

Android N'yi de çalıştırıyorum! –

cevap

0
Try This link may to be help you 

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

olduğunu

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

ve

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

çalıştı

+0

Bu, telefona ekli ekran görüntüsü gibi bir yan menü ekranı açar ve hatta içindeki kişiyi göstermez. –

0

Bu benim için çalışıyor:

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

kişi seçmek için aşağıdaki kodu deneyin:

Niyet contactPickerIntent = new Hedefi (Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI); startActivityForResult (contactPickerIntent, RESULT_PICK_CONTACT); aşağıdaki gibi

Sen onActivityResult gerekli bilgileri alabilmesi:

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

Bu çözüm benim için çalıştı! –

+0

oH .. !! Bu harika..!! –

5

Ben de aynı problem vardı. Son olarak,

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