Android Content Providers(三)——Contacts Provider

article/2025/10/20 9:50:38

接着上篇Android Content Providers(二)——Contacts Provider继续,接下来要说明的是顶层的Contacts,Contacts是聚合联系人表,在之前讨论的RawContacts是原始联系人表,在Android通讯录的架构中,分为聚合联系人、原始联系人和数据表三层。数据表主要存储数据和与原始联系人相关联的ID,Data表的字段Data在之前已经说明过,原始联系人RawContacts不直接存储数据,数据通过ID关联存储在数据表Data中,而关于聚合联系人,这里要先讲一下Android中的账户,Android可以绑定多个账户,在每一个账户下都可以有一份联系人信息,但是当我们进入通讯录,看到的其实就是聚合联系人,如果我们有多个账户,每个账户里都有同一个联系人,我们不希望看到同一个联系人重复出现很多次,所有有了聚合联系人表Contacts,Contacts同样通过ID与原始联系人表进行关联。下面看一下这三者之间的一个关系图:

                                                              

顶层显示的是聚合联系人表Contacts,中间是原始联系人表RawContacts,这里有三个账户(两个Gmail,一个Twitter)分别存储这这个联系人的信息,最底层是Data表,存储着联系人的具体信息。通过这个图可以比较直观的看出Android系统通讯录的三层架构。


在使用过程中可以通过Intent的方式来进行通讯录的修改操作,通过下面这张表可以看到有几种直接调用系统铜须路的操作方式:

Task

Action

Data

MIME type

Notes

Pick a contact from a list

ACTION_PICK

One of:

  • Contacts.CONTENT_URI, which displays a list of contacts.
  • Phone.CONTENT_URI, which displays a list of phone numbers for a raw contact.
  • StructuredPostal.CONTENT_URI, which displays a list of postal addresses for a raw contact.
  • Email.CONTENT_URI, which displays a list of email addresses for a raw contact.

Not used

Displays a list of raw contacts or a list of data from a raw contact, depending on the content URI type you supply.

CallstartActivityForResult(), which returns the content URI of the selected row. The form of the URI is the table's content URI with the row's LOOKUP_IDappended to it. The device's contacts app delegates read and write permissions to this content URI for the life of your activity. See the Content Provider Basics guide for more details.

Insert a new raw contact

Insert.ACTION

N/A

RawContacts.CONTENT_TYPE, MIME type for a set of raw contacts.

Displays the device's contacts application's Add Contactscreen. The extras values you add to the intent are displayed. If sent withstartActivityForResult(), the content URI of the newly-added raw contact is passed back to your activity'sonActivityResult()callback method in the Intentargument, in the "data" field. To get the value, callgetData().

Edit a contact

ACTION_EDIT

CONTENT_LOOKUP_URI for the contact. The editor activity will allow the user to edit any of the data associated with this contact.

Contacts.CONTENT_ITEM_TYPE, a single contact.

Displays the Edit Contact screen in the contacts application. The extras values you add to the intent are displayed. When the user clicksDone to save the edits, your activity returns to the foreground.


这里提供一种通过Intent来使用的方法,还有其他的使用方式,具体使用方式如下:

// Gets values from the UI

String name = mContactNameEditText.getText().toString();

String phone = mContactPhoneEditText.getText().toString();

String email = mContactEmailEditText.getText().toString();

String company = mCompanyName.getText().toString();

String jobtitle = mJobTitle.getText().toString();

// Creates a new intent for sending to the device's contacts application

Intent insertIntent =newIntent(ContactsContract.Intents.Insert.ACTION);

// Sets the MIME type to the one expected by the insertion activity

insertIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE);

// Sets the new contact name

insertIntent.putExtra(ContactsContract.Intents.Insert.NAME, name);

// Sets the new company and job title

insertIntent.putExtra(ContactsContract.Intents.Insert.COMPANY, company);

insertIntent.putExtra(ContactsContract.Intents.Insert.JOB_TITLE, jobtitle); 


最后,在使用系统联系人的时候,需要加上两个权限:

<uses-permission android:name="android.permission.READ_CONTACTS">

<uses-permission android:name="android.permission.WRITE_CONTACTS">


详细文档可以参考:http://developer.android.com/guide/topics/providers/contacts-provider.html


关于这部分内容我还有些理解的不是很到位的地方,后续会继续学习,感兴趣的朋友可以一起研究。

加入我们的QQ群或微信公众账号请查看: Ryan's zone公众账号及QQ群


欢迎关注我的新浪微博和我交流:@唐韧_Ryan



http://chatgpt.dhexx.cn/article/G4pcQH37.shtml

相关文章

Android contacts 的详解

一、包结构分析 相关联的的projects 1、Contacts相关 联系人分为了Contacts和ContactsCommon&#xff0c;与sim卡联系人相关的是在Telephony中&#xff0c;数据库是在ContactsProvider&#xff0c;apk要push到/system/priv-app/Contacts下 2、Contacts的包结构 3、ContactsComm…

由ContactsProvider的升级引发的OTA首次开机卡白米问题分析

上午的宁静被一个OTA卡白米问题打破&#xff0c;接下来不断有人反馈不同机型都复现了OTA后卡白米&#xff0c;10.9号OTA升级到10.10号的版本&#xff0c;全机型问题&#xff0c;线刷没有问题&#xff0c;好吧&#xff0c;接下来就根据这些信息开始初步分析log吧&#xff01; 初…

Android Content Providers(二)——Contacts Provider

Contacts Provider是Android中一个强大并且灵活的组件&#xff0c;负责管理系统通讯录的数据&#xff0c;对外提供访问接口来对系统通讯录进行访问和操作。 以下是Contacts Provider的组织结构图&#xff1a; 可以看出Android的系统通讯录是三层架构&#xff0c;通过URI进行访…

API Guides Contacts Provider (二)

Data From Sync Adapters 用户直接输入联系人的数据到设备中&#xff0c;但是也可以通过sync adapters从服务器上获取联系人的数据。sync adapter 会自动同步设备和服务器上的数据。sync adapter运行在后台&#xff0c;由系统来控制。系统调用ContentResolver去管理数据。 在A…

Android 7.0后SettingProvider ContactsProvider TelephonyProvider MediaProvider数据库位置

在Android7.0之后&#xff0c;很多Provider数据库的位置都发生了改变&#xff0c;在这记录下&#xff0c;免得以后又忘记了&#xff0c;找起来费劲。 1、SettingsProvider 在之前SettingsProvider是是以settings.db的方法存在&#xff0c;在Android N之后SettingsProvider数据存…

利用Contacts Provider读取手机联系人信息

参考:https://developer.android.google.cn/guide/topics/providers/contacts-provider.html Contacts Provider组织结构 Contacts Provider组织结构由三部分构成,如下图所示: (联系人)Contact:代表联系人,包含了多种联系渠道。(原始联系人)RawContact:每个原始联…

API Guides Contacts Provider

Contacts Provider Contacts Provider是Android的一个强大组件&#xff0c;它管理联系人的核心数据。你在手机联系人看到联系人信息&#xff0c;来源于Contact Provider。当然&#xff0c;你可以在自己的应用用访问ContactProvider的数据&#xff0c;也可以同步手机和服务…

Android官方文档—APP组件(Content Providers)(Contacts Provider)

通讯录内容提供者 Contacts Provider是一个功能强大且灵活的Android组件&#xff0c;用于管理设备的人员数据中​​央存储库。联系人提供程序是您在设备的联系人应用程序中看到的数据源&#xff0c;您还可以在自己的应用程序中访问其数据&#xff0c;并在设备和在线服务之间传…

理清contactsprovider

初步了解android contact provider android的联系人数据单独拿出来做成ContactsProvider&#xff0c;众多的table和view整体看下来&#xff0c;使得联系人的数据错综复杂。但是我们在开发的过程并不需要将所有的table都搞清楚。用到最多的是 ContactsContract.Contacts、Contac…

Android ContactsProvider源码分析

Android源码目录packages\providers下的应用是下载&#xff0c;通话等内置基本应用提供数据存储和操作的provider应用&#xff0c;本文章将针对ContactsProvider源码的架构和实现展开分析。&#xff08;注&#xff1a;本文使用使用android4.0版本进行分析&#xff09; 1、架构设…

ContactsProvider2

本篇不全也不细&#xff0c;只是根据按照个人理解和工作中遇到的问题&#xff0c;总结了个人认为的要点。 1. Android的数据库体系 1.1. 概述1.2 uri结构 2. ContactsProvider2 2.1. 概述2.2. Contacts2.db中的表2.3. ContactProvider2中的实现2.4. 批量访问 1. Android的数…

Android ContactProvider码源解析

Android Contacts源码解析2 4 ContactsProvider模块 1ContactsProvider简介2数据库创建3主要数据库的表结构相互关系 1data表2raw_contacts表3contacts表4mimetypes5其他表 文章转载自&#xff1a;https://blog.csdn.net/kafka_88/article/details/58585607 4&#xff0c;…

Contacts Provider基础

作为四大组件之一的ContentProvider工作中我们很少会用到自己自定义的ContentProvider,用到的最多的就是系统提供的。官方文档提供了两种系统ContentProvider,一种是CalendarProvider,一种是Contacts Provider。今天我们的主角就是Contact Provider。 The Contacts Provider is…

Error: invalid code, hints: [ req_id: * ]

1、问题描述&#xff1a;这个问题是在处理订单支付时需要用户登录遇到的&#xff0c;具体报错信息如下&#xff1a; 2、报错原因&#xff1a; 当前开发者的appid没有支付权限导致 3、解决方案&#xff1a; 需要负责人给分配对应的权限

This application’s bundle identifier does not match its code signing identifier.

今天使用carthage更新第三方后莫名出现真机云心失败,提示 This application’s bundle identifier does not match its code signing identifier. 解决方法: /usr/local/bin/carthage copy-frameworks 进入Building Phases 单击并在New Run Script Phase中添加脚本 将/usr/lo…

Code Sign error: a valid provisioning profile matching the application's Identifier 'com.yourcompany

出现这个错误的原因是因为&#xff1a;appid和provisioning profile不匹配 &#xff01;有两种解决的办法&#xff1a;重新下载provisioning profile&#xff0c;或者可能因为&#xff1a;生成证书和appid 所用的根证书不同&#xff0c;最好重新都生成然后下载。&#xff08;这…

ANTD react 手机号(验证码)登陆 + 账号登陆(图形验证码)

这种页面可能是大家常用的,但重写比较费时间,之前没有搜到完整的,在这里自己总结一下,方面复用 代码: <LoginFormformRef{formRef}initialValues{{autoLogin: false}}onFinish{async values > {await handleSubmit(values as LoginParams)}}><Tabs activeKey{type…

Springboot+axios+vue使用VerifyCodeUtils工具类实现验证码图片功能

一、环境准备 ideajava 1.8maven 3.6.3操作系统&#xff1a;window10vue.min.jsaxios.min.js 二、VerifyCodeUtils工具类 import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import ja…

Identity and Authentication - Common Authentication Methods

Username and Passwords This is the most common method of identifying users in the age of Software as a Service (SaaS) 解释上面的图中的步骤&#xff1a; Login Request: POST /login postuser {username: users,password: pws }Find users: SELECT * FROM databa…

iOS code signing identity 配置

PROJECT 和 TARGET 中都要选:code signing identity: 调试统一都选 developer, 发布统一都选 distribution provisioning Profile 也要选. 过期和无效的证书及时删除, 避免 ambiguous 警告. 选择正确的证书配置后仍然报错, clean 一下重启 xcode 还不行~~~重启电脑