但使书种多,会有岁稔时。这篇文章主要讲述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"/>
推荐阅读
- Android开发经验我们要友好的告诉用户,程序要崩溃了
- Docker存储驱动devicemapper介绍和配置
- Android 资源加载Resources源码分析(8.0)
- Android Cordova 插件开发之编写自己定义插件
- 浅谈存储重删压缩之三netapp的逆袭
- sqli-labs less30 GET- Blind -Impidence mismatch -Having a WAF in front of web application (GET型基于盲(代
- spring注入时报错(:No qualifying bean of type 'xxx.xxMapper')
- 吴恩达深度学习专项课程3学习笔记/week1/Setting up ML Application
- 智能手机技术飞速发展手机APP制作平台异军突起