iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >android中是如何获取联系人所有信息的
  • 142
分享到

android中是如何获取联系人所有信息的

android 2023-05-30 23:05:30 142人浏览 泡泡鱼
摘要

这篇文章将为大家详细讲解有关Android中是如何获取联系人所有信息的,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。工具类:package com.example.test;imp

这篇文章将为大家详细讲解有关Android中是如何获取联系人所有信息的,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

工具类:

package com.example.test;import java.util.ArrayList;import java.util.List;import org.JSON.jsONException;import org.json.JSONObject;import android.content.Context;import android.database.Cursor;import android.provider.ContactsContract.CommonDataKinds.Email;import android.provider.ContactsContract.CommonDataKinds.Event;import android.provider.ContactsContract.CommonDataKinds.Im;import android.provider.ContactsContract.CommonDataKinds.Nickname;import android.provider.ContactsContract.CommonDataKinds.Note;import android.provider.ContactsContract.CommonDataKinds.Organization;import android.provider.ContactsContract.CommonDataKinds.Phone;import android.provider.ContactsContract.CommonDataKinds.StructuredName;import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;import android.provider.ContactsContract.CommonDataKinds.WEBsite;import android.provider.ContactsContract.Contacts;import android.provider.ContactsContract.Data;import android.util.Log;public class ContactUtil { private List<Contacts> list; private Context context; private JSONObject contactData; private JSONObject jsonObject; public ContactUtil(Context context) { this.context = context; } // ContactsContract.Contacts.CONTENT_URI= content://com.android.contacts/contacts; // ContactsContract.Data.CONTENT_URI = content://com.android.contacts/data;  public String getContactInfo() throws JSONException { list = new ArrayList<Contacts>(); contactData = new JSONObject(); String mimetype = ""; int oldrid = -1; int contactId = -1; // 1.查询通讯录所有联系人信息,通过id排序,我们看下android联系人的表就知道,所有的联系人的数据是由RAW_CONTACT_ID来索引开的 // 所以,先获取所有的人的RAW_CONTACT_ID Cursor cursor = context.getContentResolver().query(Data.CONTENT_URI,  null, null, null, Data.RAW_CONTACT_ID); int numm = 0; while (cursor.moveToNext()) {  contactId = cursor.getInt(cursor   .getColumnIndex(Data.RAW_CONTACT_ID));  if (oldrid != contactId) {  jsonObject = new JSONObject();  contactData.put("contact" + numm, jsonObject);  numm++;  oldrid = contactId;  }  mimetype = cursor.getString(cursor.getColumnIndex(Data.MIMETYPE)); // 取得mimetype类型,扩展的数据都在这个类型里面  // 1.1,拿到联系人的各种名字  if (StructuredName.CONTENT_ITEM_TYPE.equals(mimetype)) {  cursor.getString(cursor   .getColumnIndex(StructuredName.DISPLAY_NAME));  String prefix = cursor.getString(cursor   .getColumnIndex(StructuredName.PREFIX));  jsonObject.put("prefix", prefix);  String firstName = cursor.getString(cursor   .getColumnIndex(StructuredName.FAMILY_NAME));  jsonObject.put("firstName", firstName);  String middleName = cursor.getString(cursor   .getColumnIndex(StructuredName.MIDDLE_NAME));  jsonObject.put("middleName", middleName);  String lastname = cursor.getString(cursor   .getColumnIndex(StructuredName.GIVEN_NAME));  jsonObject.put("lastname", lastname);  String suffix = cursor.getString(cursor   .getColumnIndex(StructuredName.SUFFIX));  jsonObject.put("suffix", suffix);  String phoneticFirstName = cursor.getString(cursor   .getColumnIndex(StructuredName.PHONETIC_FAMILY_NAME));  jsonObject.put("phoneticFirstName", phoneticFirstName);  String phoneticMiddleName = cursor.getString(cursor   .getColumnIndex(StructuredName.PHONETIC_MIDDLE_NAME));  jsonObject.put("phoneticMiddleName", phoneticMiddleName);  String phoneticLastName = cursor.getString(cursor   .getColumnIndex(StructuredName.PHONETIC_GIVEN_NAME));  jsonObject.put("phoneticLastName", phoneticLastName);  }  // 1.2 获取各种电话信息  if (Phone.CONTENT_ITEM_TYPE.equals(mimetype)) {  int phoneType = cursor   .getInt(cursor.getColumnIndex(Phone.TYPE)); // 手机  if (phoneType == Phone.TYPE_MOBILE) {   String mobile = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("mobile", mobile);  }  // 住宅电话  if (phoneType == Phone.TYPE_HOME) {   String homeNum = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("homeNum", homeNum);  }  // 单位电话  if (phoneType == Phone.TYPE_WORK) {   String jobNum = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("jobNum", jobNum);  }  // 单位传真  if (phoneType == Phone.TYPE_FAX_WORK) {   String workFax = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("workFax", workFax);  }  // 住宅传真  if (phoneType == Phone.TYPE_FAX_HOME) {   String homeFax = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("homeFax", homeFax);  } // 寻呼机  if (phoneType == Phone.TYPE_PAGER) {   String pager = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("pager", pager);  }  // 回拨号码  if (phoneType == Phone.TYPE_CALLBACK) {   String quickNum = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("quickNum", quickNum);  }  // 公司总机  if (phoneType == Phone.TYPE_COMPANY_MAIN) {   String jobTel = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("jobTel", jobTel);  }  // 车载电话  if (phoneType == Phone.TYPE_CAR) {   String carNum = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("carNum", carNum);  } // ISDN  if (phoneType == Phone.TYPE_ISDN) {   String isdn = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("isdn", isdn);  } // 总机  if (phoneType == Phone.TYPE_MAIN) {   String tel = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("tel", tel);  }  // 无线装置  if (phoneType == Phone.TYPE_RADIO) {   String wirelessDev = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("wirelessDev", wirelessDev);  } // 电报  if (phoneType == Phone.TYPE_TELEX) {   String telegram = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("telegram", telegram);  }  // TTY_TDD  if (phoneType == Phone.TYPE_TTY_TDD) {   String tty_tdd = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("tty_tdd", tty_tdd);  }  // 单位手机  if (phoneType == Phone.TYPE_WORK_MOBILE) {   String jobMobile = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("jobMobile", jobMobile);  }  // 单位寻呼机  if (phoneType == Phone.TYPE_WORK_PAGER) {   String jobPager = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("jobPager", jobPager);  } // 助理  if (phoneType == Phone.TYPE_ASSISTANT) {   String assistantNum = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("assistantNum", assistantNum);  } // 彩信  if (phoneType == Phone.TYPE_MMS) {   String mms = cursor.getString(cursor    .getColumnIndex(Phone.NUMBER));   jsonObject.put("mms", mms);  }  String mobileEmail = cursor.getString(cursor   .getColumnIndex(Email.DATA));  jsonObject.put("mobileEmail", mobileEmail);  } } // 查找event地址 if (Event.CONTENT_ITEM_TYPE.equals(mimetype)) { // 取出时间类型  int eventType = cursor.getInt(cursor.getColumnIndex(Event.TYPE)); // 生日  if (eventType == Event.TYPE_BIRTHDAY) {  String birthday = cursor.getString(cursor   .getColumnIndex(Event.START_DATE));  jsonObject.put("birthday", birthday);  }  // 周年纪念日  if (eventType == Event.TYPE_ANNIVERSARY) {  String anniversary = cursor.getString(cursor   .getColumnIndex(Event.START_DATE));  jsonObject.put("anniversary", anniversary);  } } // 获取即时通讯消息 if (Im.CONTENT_ITEM_TYPE.equals(mimetype)) { // 取出即时消息类型  int protocal = cursor.getInt(cursor.getColumnIndex(Im.PROTOCOL));  if (Im.TYPE_CUSTOM == protocal) {  String workMsg = cursor.getString(cursor   .getColumnIndex(Im.DATA));  jsonObject.put("workMsg", workMsg);  } else if (Im.PROTOCOL_MSN == protocal) {  String workMsg = cursor.getString(cursor   .getColumnIndex(Im.DATA));  jsonObject.put("workMsg", workMsg);  }  if (Im.PROTOCOL_QQ == protocal) {  String instantsMsg = cursor.getString(cursor   .getColumnIndex(Im.DATA));  jsonObject.put("instantsMsg", instantsMsg);  } } // 获取备注信息 if (Note.CONTENT_ITEM_TYPE.equals(mimetype)) {  String remark = cursor.getString(cursor.getColumnIndex(Note.NOTE));  jsonObject.put("remark", remark); } // 获取昵称信息 if (Nickname.CONTENT_ITEM_TYPE.equals(mimetype)) {  String nickName = cursor.getString(cursor   .getColumnIndex(Nickname.NAME));  jsonObject.put("nickName", nickName); } // 获取组织信息 if (Organization.CONTENT_ITEM_TYPE.equals(mimetype)) { // 取出组织类型  int orgType = cursor.getInt(cursor   .getColumnIndex(Organization.TYPE)); // 单位  if (orgType == Organization.TYPE_CUSTOM) { // if (orgType ==       // Organization.TYPE_WORK)       // {  String company = cursor.getString(cursor   .getColumnIndex(Organization.COMPANY));  jsonObject.put("company", company);  String jobTitle = cursor.getString(cursor   .getColumnIndex(Organization.TITLE));  jsonObject.put("jobTitle", jobTitle);  String department = cursor.getString(cursor   .getColumnIndex(Organization.DEPARTMENT));  jsonObject.put("department", department);  } } // 获取网站信息 if (Website.CONTENT_ITEM_TYPE.equals(mimetype)) { // 取出组织类型  int webType = cursor.getInt(cursor.getColumnIndex(Website.TYPE)); // 主页  if (webType == Website.TYPE_CUSTOM) {  String home = cursor.getString(cursor   .getColumnIndex(Website.URL));  jsonObject.put("home", home);  } // 主页  else if (webType == Website.TYPE_HOME) {  String home = cursor.getString(cursor   .getColumnIndex(Website.URL));  jsonObject.put("home", home);  }  // 个人主页  if (webType == Website.TYPE_HOMEPAGE) {  String homePage = cursor.getString(cursor   .getColumnIndex(Website.URL));  jsonObject.put("homePage", homePage);  }  // 工作主页  if (webType == Website.TYPE_WORK) {  String workPage = cursor.getString(cursor   .getColumnIndex(Website.URL));  jsonObject.put("workPage", workPage);  } } // 查找通讯地址 if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimetype)) { // 取出邮件类型  int postalType = cursor.getInt(cursor   .getColumnIndex(StructuredPostal.TYPE)); // 单位通讯地址  if (postalType == StructuredPostal.TYPE_WORK) {  String street = cursor.getString(cursor   .getColumnIndex(StructuredPostal.STREET));  jsonObject.put("street", street);  String ciry = cursor.getString(cursor   .getColumnIndex(StructuredPostal.CITY));  jsonObject.put("ciry", ciry);  String box = cursor.getString(cursor   .getColumnIndex(StructuredPostal.POBOX));  jsonObject.put("box", box);  String area = cursor.getString(cursor   .getColumnIndex(StructuredPostal.NEIGHBORHOOD));  jsonObject.put("area", area);  String state = cursor.getString(cursor   .getColumnIndex(StructuredPostal.REGION));  jsonObject.put("state", state);  String zip = cursor.getString(cursor   .getColumnIndex(StructuredPostal.POSTCODE));  jsonObject.put("zip", zip);  String country = cursor.getString(cursor   .getColumnIndex(StructuredPostal.COUNTRY));  jsonObject.put("country", country);  }  // 住宅通讯地址  if (postalType == StructuredPostal.TYPE_HOME) {  String homeStreet = cursor.getString(cursor   .getColumnIndex(StructuredPostal.STREET));  jsonObject.put("homeStreet", homeStreet);  String homeCity = cursor.getString(cursor   .getColumnIndex(StructuredPostal.CITY));  jsonObject.put("homeCity", homeCity);  String homeBox = cursor.getString(cursor   .getColumnIndex(StructuredPostal.POBOX));  jsonObject.put("homeBox", homeBox);  String homeArea = cursor.getString(cursor   .getColumnIndex(StructuredPostal.NEIGHBORHOOD));  jsonObject.put("homeArea", homeArea);  String homeState = cursor.getString(cursor   .getColumnIndex(StructuredPostal.REGION));  jsonObject.put("homeState", homeState);  String homeZip = cursor.getString(cursor   .getColumnIndex(StructuredPostal.POSTCODE));  jsonObject.put("homeZip", homeZip);  String homeCountry = cursor.getString(cursor   .getColumnIndex(StructuredPostal.COUNTRY));  jsonObject.put("homeCountry", homeCountry);  }  // 其他通讯地址  if (postalType == StructuredPostal.TYPE_OTHER) {  String otherStreet = cursor.getString(cursor   .getColumnIndex(StructuredPostal.STREET));  jsonObject.put("otherStreet", otherStreet);  String otherCity = cursor.getString(cursor   .getColumnIndex(StructuredPostal.CITY));  jsonObject.put("otherCity", otherCity);  String otherBox = cursor.getString(cursor   .getColumnIndex(StructuredPostal.POBOX));  jsonObject.put("otherBox", otherBox);  String otherArea = cursor.getString(cursor   .getColumnIndex(StructuredPostal.NEIGHBORHOOD));  jsonObject.put("otherArea", otherArea);  String otherState = cursor.getString(cursor   .getColumnIndex(StructuredPostal.REGION));  jsonObject.put("otherState", otherState);  String otherZip = cursor.getString(cursor   .getColumnIndex(StructuredPostal.POSTCODE));  jsonObject.put("otherZip", otherZip);  String otherCountry = cursor.getString(cursor   .getColumnIndex(StructuredPostal.COUNTRY));  jsonObject.put("otherCountry", otherCountry);  } } cursor.close(); Log.i("contactData", contactData.toString()); return contactData.toString(); }}

关于android中是如何获取联系人所有信息的就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

--结束END--

本文标题: android中是如何获取联系人所有信息的

本文链接: https://www.lsjlt.com/news/222095.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • android中是如何获取联系人所有信息的
    这篇文章将为大家详细讲解有关android中是如何获取联系人所有信息的,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。工具类:package com.example.test;imp...
    99+
    2023-05-30
    android
  • Android利用ContentProvider获取联系人信息
    本文实例为大家分享了Android利用ContentProvider获取联系人信息的具体代码,供大家参考,具体内容如下 在写代码前我们首先看一下运行的效果 运行效果如下: 点了获取...
    99+
    2024-04-02
  • Android中是如何获取手机联系人的
    这篇文章给大家介绍Android中是如何获取手机联系人的,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。Android 获取系统联系人信息的实例一、获取手机联系人姓名及手机号//跳转到系统联系人应用 Inten...
    99+
    2023-05-30
    android
  • 如何在Android应用中利用Intent实现获取联系人的信息
    今天就跟大家聊聊有关如何在Android应用中利用Intent实现获取联系人的信息,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。Intent的使用intent是一个好东西他可以启动A...
    99+
    2023-05-31
    android intent
  • 如何在Android中获取系统储存信息
    这篇文章给大家介绍如何在Android中获取系统储存信息,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。获取SD卡上的储存信息:    private String&nb...
    99+
    2023-05-30
    android
  • 微信小程序中如何获取系统信息
    这篇“微信小程序中如何获取系统信息”文章,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要参考一下,对于“微信小程序中如何获取系统信息”,小编整理了以下知识点,请大家跟着小编的步伐一步一步的慢慢理解,接下来就让我们进入...
    99+
    2023-06-26
  • C#中如何获取系统信息的Windows窗体
    这篇文章主要为大家展示了“C#中如何获取系统信息的Windows窗体”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“C#中如何获取系统信息的Windows窗体”这篇文章吧。C#程序设计获取系统信息...
    99+
    2023-06-17
  • Android应用中怎么获取联系人的姓名与电话
    这期内容当中小编将会给大家带来有关Android应用中怎么获取联系人的姓名与电话,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。实现代码:<&#63;xml version="1.0...
    99+
    2023-05-31
    android roi
  • 如何在Android中使用CrashHandler获取应用的crash信息
    如何在Android中使用CrashHandler获取应用的crash信息?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。一、Thread 类中的 setDefa...
    99+
    2023-05-30
    android crash crashhandler
  • VB.NET中如何获取硬盘信息
    VB.NET中如何获取硬盘信息,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。VB.NET获取硬盘信息之一:用API函数GetDiskFreeSpaceEx获取磁...
    99+
    2023-06-17
  • 如何在android 中获取本机其他app的版本信息
    如何在android 中获取本机其他app的版本信息?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。先建一个实体类,用来存放app信息。package ...
    99+
    2023-05-30
    android
  • 小程序开发中如何获取系统信息
    本文将为大家详细介绍“小程序开发中如何获取系统信息”,内容步骤清晰详细,细节处理妥当,而小编每天都会更新不同的知识点,希望这篇“小程序开发中如何获取系统信息”能够给你意想不到的收获,请大家跟着小编的思路慢慢深入,具体内容如下,一起去收获新知...
    99+
    2023-06-26
  • Python如何使用psutil获取系统信息
    三、psutil用Python来编写脚本简化日常的运维工作是Python的一个重要用途。在Linux下,有许多系统命令可以让我们时刻监控系统运行的状态,如ps,top,free等等。要获取这些系统信息,Python可以通过subproces...
    99+
    2023-05-15
    Python psutil
  • JVM中如何获取OOM时的堆信息
    这篇文章给大家分享的是有关JVM中如何获取OOM时的堆信息的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。JVM的框架知识了解之后,实际的项目里发生了OOM异常的话,怎么获取以及分析异常信息后怎么分析呢。这里稍微做...
    99+
    2023-05-31
    jvm oom
  • java中如何获取map的所有键
    在Java中,可以使用`keySet()`方法获取Map的所有键。该方法返回一个Set集合,其中包含Map中所有的键。以下是一个示例...
    99+
    2023-08-31
    java
  • Android系统服务是如何获取的
    目录关于获取系统服务的猜想获取系统服务源码实现真正的系统服务提供者关于获取系统服务的猜想 Android获取系统服务一般都需要用getSystemService指定系统服务名称获取...
    99+
    2024-04-02
  • Linux下如何使用Inxi获取系统信息
    这篇文章给大家分享的是有关Linux下如何使用Inxi获取系统信息的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。Inxi 最初是为控制台和 IRC(网络中继聊天)开发的一个强大且优秀的命令行系统信息脚本。可以使用...
    99+
    2023-06-27
  • vue3如何实现微信扫码登录及获取个人信息
    这篇文章主要讲解了“vue3如何实现微信扫码登录及获取个人信息”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“vue3如何实现微信扫码登录及获取个人信息”吧!一、流程:微信提供的扫码方式有两种...
    99+
    2023-07-06
  • Android应用中是如何获取系统语言的
    Android应用中是如何获取系统语言的?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。获取系统当前语言是一个比较常用的功能,在 Android 7.0 系统上旧函数获取到的当前...
    99+
    2023-05-31
    android roi
  • ASP和Unix系统的API:如何快速获得所需信息?
    随着信息时代的到来,人们对于信息获取的需求越来越高。如何快速获取所需信息成为了一个重要的问题。在这个问题上,ASP和Unix系统的API可以提供一些很好的解决方案。 ASP(Active Server Pages)是一种动态网页技术,它可...
    99+
    2023-08-29
    unix 关键字 api
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作