I have read the already posted solutions, but they dont tell how do I use system\'s contact details screen to select any ONE number to use? I am developing an sms sending an
There is a problem in the accepted answer.
If the number selected contains spaces within it
i.e. 85 29 948789
then it will show only 85 (until first space).
so use the below code to rectify this problem :)
Intent intent1 = new Intent(Intent.ACTION_PICK);
intent1.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent1, 1);
and in onActivityResult
Uri contactUri = data.getData();
String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
Cursor cursor = getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
int numberColumn = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int nameColumn = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String number = cursor.getString(numberColumn);
String name = cursor.getString(nameColumn);