搜索手机联系人所有字段
想取手机联系人的有效字段,但是苦于找不到API表示的字段变量,所以采用下边笨办法:
private void getPhoneContacts() {
ContentResolver resolver = mContext.getContentResolver();
Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,PHONES_PROJECTION, null, null,"sort_key");
System.out.println("..........."+phoneCursor.getColumnCount());
int indexContacter=0;
if (phoneCursor != null) {
phoneCursor.moveToPosition(120);//120位置的联系人为例子,
// 根据数据库列数,列出所有的字段名字大概63个
for(int i=0;i<phoneCursor.getColumnCount();i++){
System.out.println(">>>>>.: "+phoneCursor.getString(i)+" "+phoneCursor.getColumnName(i));
}
}
然后可以根据列出的字段名取有用的数据,可以直接用String表示,省得找不到对应的变量
private static final String[] PHONES_PROJECTION = new String[] {
Phone.DISPLAY_NAME, Phone.NUMBER, Photo.PHOTO_ID,Phone.CONTACT_ID,"sort_key"};
Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,PHONES_PROJECTION, null, null,"sort_key");