• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
lisztkao
博客园    首页    新随笔    联系   管理    订阅  订阅

聯絡人名稱 與 電話

名稱

static final String[] CONTACTS_PROJECTION = new String[] {
  ContactsContract.Contacts._ID,
  ContactsContract.Contacts.PHOTO_ID,
  ContactsContract.Contacts.DISPLAY_NAME,
  ContactsContract.Contacts.HAS_PHONE_NUMBER,
};
Cursor cur = contentResolver.query(
ContactsContract.Contacts.CONTENT_URI, new String[] {CONTACTS_PROJECTION, null, null, ContactsContract.Contacts._ID);
try {
  if (cur.moveToFirst()) {
	int idCol = cur.getColumnIndex(ContactsContract.Contacts._ID);
	int photoCol = cur.getColumnIndex(ContactsContract.Contacts.PHOTO_ID);
	int displayNameCol = cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
	int hasPhoneNumberCol = cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
	do {
		long id = cur.getLong(idCol);
		long photoId = cur.getLong(photoCol);
		String name = cur.getString(displayNameCol);
		boolean hasPhoneNumber = cur.getInt(hasPhoneNumberCol) != 0;
		// contactsMap.put(id, contact);
	} while (cur.moveToNext());
  }
} finally {
  cur.close();
}
 


電話

	static final String[] COMMONDATAKIND_PHONE_PROJECTION = new String[]{
	CommonDataKinds.Phone.CONTACT_ID,
        CommonDataKinds.Phone.TYPE,
        CommonDataKinds.Phone.NUMBER,
        CommonDataKinds.Phone.IS_PRIMARY,
};

Cursor cur = contentResolver.query(CommonDataKinds.Phone.CONTENT_URI,
				COMMONDATAKIND_PHONE_PROJECTION, null, null,
				CommonDataKinds.Phone.CONTACT_ID);
try {
  if (cur.moveToFirst()) {
	int idCol = cur.getColumnIndex(CommonDataKinds.Phone.CONTACT_ID);
	int typeCol = cur.getColumnIndex(CommonDataKinds.Phone.TYPE);
	int numberCol = cur.getColumnIndex(CommonDataKinds.Phone.NUMBER);
	int isPrimaryCol = cur	.getColumnIndex(CommonDataKinds.Phone.IS_PRIMARY);
	do {
		long id = cur.getLong(idCol);
		int type = cur.getInt(typeCol);
		String number = cur.getString(numberCol);
		boolean primary = cur.getInt(isPrimaryCol) != 0;
		if (number != null) {
			;
		}
	} while (cur.moveToNext());
  }
 } finally {   cur.close(); }
posted @ 2011-06-22 15:24  Lisztkao  阅读(266)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3