This is a good tutorial on how to get a contact number using android content provider
http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/
and
http://www.app-solut.com/blog/2012/06/retrieval-of-contacts-with-contact-contract/
and can choose a contact number like this
add button click event e.g.
button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(i, PICK_CONTACT); } }); //outside button click public void onActivityResult(int reqCode, int resultCode, Intent data) { super.onActivityResult(reqCode, resultCode, data); switch (reqCode) { case (PICK_CONTACT): if (resultCode == Activity.RESULT_OK) { getContactInfo(data); } } } // onActivityResult private void getContactInfo(Intent data) { // TODO Auto-generated method stub ContentResolver cr = getContentResolver(); Cursor cursor = managedQuery(data.getData(), null, null, null, null); while (cursor.moveToNext()) { String contactId = cursor.getString(cursor .getColumnIndex(ContactsContract.Contacts._ID)); Name = cursor .getString(cursor .getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); String hasPhone = cursor .getString(cursor .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); Cursor emailCur = cr.query( ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{contactId}, null); emailCur.close(); if (hasPhone.equalsIgnoreCase("1")) hasPhone = "true"; else hasPhone = "false"; if (Boolean.parseBoolean(hasPhone)) { Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); while (phones.moveToNext()) { phoneNo = phones .getString(phones .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); } phones.close(); } pname.setText(Name); // phno.setText(phoneNo); Toast.makeText(this, Name + " " + phoneNo, Toast.LENGTH_SHORT).show(); } }
source share