1 .申请权限 <uses-permission android:name= "android.permission.READ_CONTACTS" /> |
2 .示例: |
Cursor cursor= null ; |
cursor=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null , null , null , null ); |
if (cursor!= null ) |
{ |
while (cursor.moveToNext()) |
{ |
//获取姓名 |
String name=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); |
//获取手机号 |
String phone=cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); |
textView.append(name+ " " +phone+ "\n" ); |
} |
} |
3 .不加权限会崩溃,Android6. 0 以上,使用了运行时权限,在此代码的基础上还要增加一些内容 |
by: 发表于:2017-09-26 11:43:36 顶(0) | 踩(0) 回复
??
回复评论