android, contentProvider 获取通讯录

1.6获取方法

ContentResolver resolver = getContentResolver();
Cursor cursorPhone = resolver.query(People.CONTENT_URI,
null,null , null,null);

2.1 获取方法

ContentResolver resolver = getContentResolver();
Cursor cursorPhone = resolver.query(ContactsContract.Contacts.CONTENT_URI
null,null , null,null);

1.6将电话号码也放在同一个ContentProvider里,

而2.1将号码放到了ContactsContract.CommonDataKinds.Phone.CONTENT_URI

仅获取手机号码:

ContentResolver resolver = getContentResolver();

Cursor cursorPhone = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.TYPE+"="+ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE , null,null);




记得在Manifest.xml里加上访问通讯录的权限:

你可能感兴趣的:(android)