您的位置:首页 > 移动开发 > Android开发

使用Intent.ACTION_EDIT 调用系统编辑联系人

2015-11-06 11:40 357 查看
参看官方文档:http://developer.android.com/guide/topics/providers/contacts-provider.html#Access 的Retrieval
and modification with intents 部分:

本文讨论的是编辑指定的联系人,否则你应该使用Intent.ACTION_INSERT_OR_EDIT

涉及到的Action是:Intent.ACTION_EIDT 
涉及到的Provider契约类常量是:
Contacts.CONTENT_LOOKUP_URI  指定相关联系人的URI
Contacts.CONTENT_ITEM_TYPE  指定联系人的MIME类型

重点是如何构建一个指定联系人的Contacts.CONTENT_LOOKUP_URI

官网对Contacts.CONTENT_LOOKUP_URI的说明是:

A content:// style URI for this table that should be used to create shortcuts or otherwise create long-term links to contacts. This URI should always be followed by a "/" and the contact's LOOKUP_KEY.
It can optionally also have a "/" and last known contact ID appended after that. This "complete" format is an important optimization and is highly recommended.

As long as the contact's row ID remains the same, this URI is equivalent to CONTENT_URI.
If the contact's row ID changes as a result of a sync or aggregation, this URI will look up the contact using indirect information (sync IDs or constituent raw contacts).

Lookup key should be appended unencoded - it is stored in the encoded form, ready for use in a URI.

以上大致意思是,可以通过如下两种方式构建:

第一种:

?
第二种:

?
首先是如何获得联系人的LOOKUP_KEY和ID,通常情况下,当你使用Intent.ACTION_EDIT方式时,说明你已经拿到了一个CONTENT_LOOKUP_URI,为了对以上代码更好的说明和方便起见我们通过如下代码块打开联系人应用,从中挑选一个联系人加以说明:

?
通过以上步骤就拿到了content_lookup_uri,通过下面代码块来对指定联系人进行编辑

?
当然多数时候我们直接使用Intent.ACTION_INSERT_OR_EDIT来编辑联系人 本文只是讨论在使用Intent.ACTION_EDIT时的注意事项
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息