你可以用这种方式。
在您的 onClick 中打开联系人列表的位置。
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 0);
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
if (0 == reqCode) {
if (resultCode == Activity.RESULT_OK) {
System.out.println("in on ActivityResult");
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();
cNumber = phones.getString(phones.getColumnIndex("data1"));
name=phones.getString(phones.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
//here you can find out all the thing.
System.out.println("NAME:"+name);
etFirst.setText(cNumber);
}
}
}
}
}
权限
将读取联系人数据的权限添加到您的应用程序清单。
<uses-permission android:name="android.permission.READ_CONTACTS"/>
如果您发现任何问题,请告诉我。享受..