0
use this code to pick contact:
- Button button = (Button)findViewById(R.id.pickcontact);
-
- button.setOnClickListener(new OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
- startActivityForResult(intent, PICK_CONTACT);
- }
- });
-
-
-
- @Override public void onActivityResult(int reqCode, int resultCode, Intent data){ super.onActivityResult(reqCode, resultCode, data);
-
- switch(reqCode)
- {
- case (PICK_CONTACT):
- if (resultCode == Activity.RESULT_OK)
- {
- Uri contactData = data.getData();
- Cursor c = managedQuery(contactData, null, null, null, null);
- if (c.moveToFirst())
- {
- String id = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
-
- String hasPhone =
- c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
-
- if (hasPhone.equalsIgnoreCase("1"))
- {
- Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
- ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id,null, null);
- phones.moveToFirst();
- String cNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
-
- setCn(cNumber);
- }
- }
- }
- }
- }
and also refer the following Links :
https://developer.android.com/training/contacts-provider/index.html
https://stackoverflow.com/questions/6253029/how-to-get-contacts-from-native-phonebook-in-android
https://stackoverflow.com/questions/5662473/how-to-import-contacts-from-phonebook-to-our-application
