android > 获取 通讯录 信息
16lz
2021-01-23
public void getContact(){ //得到ContentResolver对象 ContentResolver cr = getContentResolver(); //取得电话本中开始一项的光标 Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); //向下移动光标 while(cursor.moveToNext()) { //取得联系人名字 int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); String contact = cursor.getString(nameFieldColumnIndex); //取得电话号码 String ContactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+ ContactId, null, null); while(phone.moveToNext()) { String PhoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); String re = (contact +":"+ PhoneNumber +"\n"); Log.d("log1", re); } } cursor.close(); }
权限
<uses-permission android:name="android.permission.READ_CONTACTS"/>
更多相关文章
- android关于EditText取消默认焦点及触摸其它地方去掉光标隐藏键
- EditText的光标选择(android.text.Selection)&输入指定字符
- EditText显示光标
- EditText 行间距 以及光标高度和样式
- 【EditText】Android 中设置 EditText 光标颜色
- edittext光标不闪烁的问题