我可以扩展Android的通讯录数据库吗? [英] Can I extend Androids Contacts database?

查看:98
本文介绍了我可以扩展Android的通讯录数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以扩展Android Contacts数据库?

I was wondering is it possible to extend the Android Contacts database?

从此处开始- http://d.android.com/reference/android/provider/ContactsContract. html

它说:

ContactsContract定义了一个可扩展的 联系人相关数据库 信息

ContactsContract defines an extensible database of contact-related information

Extensible会建议我可以在常规值(例如姓名,电话号码,电子邮件,工作号码,家庭电话等)之外添加更多数据到联系人应用程序.

Extensible would suggest to me that I can add in more data to the contacts application outside the normal values such as Name, number, email, work number, home number etc..

不过,此页面的示例- http://d.android.com/reference/android/provider/ContactsContract.RawContacts.html 仅显示如何插入名称之类的标准值,而不显示如何向联系人添加新字段.

However the examples of this page - http://d.android.com/reference/android/provider/ContactsContract.RawContacts.html only show how to insert the standard values like name and not how to add a new field to a contact.

此外,在网络上进行搜索并不会提供太多有关扩展联系人数据的信息.

Furthermore a search on the web does not turn up much information on extending the contacts data.

所以我想知道是否有可能,或者可扩展性是否指向联系人的其他部分?

So I was wondering is it even possible or does the extensible refer to some other part of the contacts?

例如,我想为在我的应用程序中具有特殊特权的联系人添加一个附加字段,以便当用户查看联系人时,他或她知道可以与我的应用程序一起使用的用户.

For example I would like to add in an additional field for contacts that have special privileges within my app so when a user looks at the contacts he or she knows what users they can use my app with.

这可能吗?

推荐答案

您可以在联系人数据库中存储自定义数据.但是,如果您认为用户在使用内置Android联系人时将能够看到您插入的自定义数据,则当用户查看联系人时,他或她知道可以与我的应用程序一起使用的用户".应用.您必须在自己的应用程序中显示自定义数据.

You can store custom data in the contacts database. However "when a user looks at the contacts he or she knows what users they can use my app with," may not be possible if you are thinking users will be able to see the custom data you inserted while using the built-in Android Contacts application. You would have to display the custom data in your own application.

ContactsContract.Data 类的Javadocs应该提供说明,以及联系人"文章.

The javadocs for the ContactsContract.Data class should provide an explanation, as well as the Contacts article.

要使用此功能,您需要通过查询

To use this you'll need to get a raw contact id by querying the RawContacts.

这里有一些示例代码可能会帮助您入门...

Here some example code that might help you get started...

private void makePowerful(int rawContactId) {
    ContentValues values = new ContentValues();
    values.put(Privilege.RAW_CONTACT_ID, rawContactId);
    values.put(Privilege.MIMETYPE, Privilege.CONTENT_ITEM_TYPE);
    values.put(Privilege.PRIVILEGE_LEVEL, Privilege.TYPE_POWERFUL);
    Uri uri = getContentResolver().insert(Data.CONTENT_URI, values);
}

public static final class Privilege implements ContactsContract.DataColumnsWithJoins, ContactsContract.CommonDataKinds.CommonColumns {
    public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/my_app_privilege";
    public static final int TYPE_POWERFUL = 1;
    public static final int TYPE_WEAK = 2;
    public static final String PRIVILEGE_LEVEL = DATA1;

    private Privilege() { }
}

这篇关于我可以扩展Android的通讯录数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆