试试下面的代码:
1)在单击关闭按钮上尝试以下操作:
Intent in = new Intent(Intent.ACTION_INSERT);
in.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(in,ADD_DATA);
2) ONActivityResult 方法:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ADD_DATA:
if(resultCode == RESULT_OK) {
Uri contactData = data.getData();
Cursor cur = managedQuery(contactData, null, null, null, null);
ContentResolver contect_resolver = getContentResolver();
if (cur.moveToFirst()) {
String id = cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
String lookupkey = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY));
String name = "";
String no = "";
Cursor phoneCur = contect_resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
if (phoneCur.moveToFirst()) {
name = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
no = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String lookup = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY));
System.out.println("Contact Name"+name);
System.out.println("Number"+no);
id = null;
name = null;
no = null;
phoneCur = null;
contect_resolver = null;
cur = null;
}
}
}
if(resultCode == RESULT_CANCELED)
{
}
break;
default:
break;
}
}