在自己的程序中调用联系人列表,然后选择某个联系人,返回该联系人的Uri
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setData(Contacts.People.CONTENT_URI);
startActivity(intent);
startActivityForResult(intent, 0);
Intent i = new Intent(Intent.ACTION_PICK);
i.setType("vnd.android.cursor.dir/phone");
startActivityForResult(i, 0);
获取选择的号码:
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 0:
if (data == null) {
return;
}
Uri uri = data.getData();
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
String number = cursor.getString(cursor.getColumnIndexOrThrow(Phones.NUMBER));
Log.d(TAG, "number" + number);
mContactText.setText(number);
mContactText.setSelection(number.length());
break;
default:
break;
}
}