我可以扩展 Android 联系人数据库吗?

发布于 2024-10-12 19:58:21 字数 769 浏览 3 评论 0原文

我想知道是否可以扩展 Android 联系人数据库?

从这里 - http://d.android.com/reference/android/provider/ContactsContract.html

它说:

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

可扩展会建议我,我可以在正常值(例如姓名、号码、电子邮件、工作号码、家庭号码等)之外向联系人应用程序添加更多数据。

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

此外,在网络上搜索并没有找到太多关于扩展联系人数据的信息。

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

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

这可能吗?

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

From here - http://d.android.com/reference/android/provider/ContactsContract.html

It says:

ContactsContract defines an extensible
database of contact-related
information

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..

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.

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合约呢 2024-10-19 19:58:21

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

ContactsContract.Data 类的 javadoc 应该提供解释,以及联系人文章

要使用此功能,您需要通过查询 RawContacts 来获取原始联系人 ID

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

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() { }
}

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.

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() { }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文