当前位置:首页 > 开发 > 移动开发 > 正文

Android读取联系人并按照拼音排序

发表于: 2011-08-11   作者:酷的飞上天空   来源:转载   浏览:
摘要: android系统1.6中 读取联系人:   cursor = cr.query(People.CONTENT_URI, null, null, null, "name desc"); //取得联系人名次 name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.D

android系统1.6中 读取联系人:

 

cursor = cr.query(People.CONTENT_URI, null, null, null, "name desc");			//取得联系人名次
			name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
			//取得联系人id
			String id = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID));
			//构造查询条件,根据联系人id为条件,查询手机号字段的信息
			String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID+" = ? and "+ContactsContract.CommonDataKinds.Phone.TYPE+" = ?";
			String[] selectionArgs = {id,"2"};
			cursorSingle = cr.query(Uri.parse("content://com.android.contacts/data/phones"), new String[]{"data1"}, selection, selectionArgs, null);
cursorSingle.moveToNext();
mobile = cursorSingle.getString(0);
 

  获取联系人名称和手机号

 

			cursor.moveToNext();
			name = cursor.getString(cursor.getColumnIndex(Phones.NAME));
			mobile = cursor.getString(cursor.getColumnIndex(Phones.NUMBER));

 

android系统2.2中  读取联系人,此时只是取到名称以及联系人的id,还要根据id获取手机号码

 

cursor = cr.query("content://com.android.contacts/contacts", null, null, null, "sort_key asc");

 获取联系人名称和手机号码

			//取得联系人名次
			name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
			//取得联系人id
			String id = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID));
			//构造查询条件,根据联系人id为条件,查询手机号字段的信息
			String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID+" = ? and "+ContactsContract.CommonDataKinds.Phone.TYPE+" = ?";
			String[] selectionArgs = {id,"2"};
			cursorSingle = cr.query(Uri.parse("content://com.android.contacts/data/phones"), new String[]{"data1"}, selection, selectionArgs, null);
			cursorSingle.moveToNext();
			mobile = cursorSingle.getString(0);
 

Android读取联系人并按照拼音排序

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号