Android 选择通讯录联系人回显

但使书种多,会有岁稔时。这篇文章主要讲述Android 选择通讯录联系人回显相关的知识,希望能为你提供帮助。
1.启动系统选择联系人界面
Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 0);
【Android 选择通讯录联系人回显】 
2.重写OnActivityResult方法获取数据

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(data!=null){
switch (requestCode)
{
case 0:
Uri conatctData= https://www.songbingjia.com/android/data.getData();
Cursor cursor = managedQuery(conatctData, null, null, null, null);
if (cursor.moveToFirst()) {
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String names = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)) ;
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+contactId, null, null);
String phonenum="";
if (phones.moveToFirst()) {
phonenum = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
name.setText(names);
phone.setText(phonenum);
if (Build.VERSION.SDK_INT < 14) {
phones.close();
}
}
if (Build.VERSION.SDK_INT < 14) {//不添加的话android4.0以上系统运行会报错
cursor.close();
}
break;
}

}

}

3.添加权限

< uses-permission android:name="android.permission.READ_CONTACTS"/>














































    推荐阅读