Android 添加联系人电子邮件

发布于 2024-09-14 12:37:32 字数 1661 浏览 4 评论 0原文

我正在尝试将新联系人插入 Android 联系人列表。添加姓名和电话号码工作正常,但添加电子邮件地址不起作用。我的代码:

//name is a string
//phone and email are string arrays
ContentValues values = new ContentValues();
values.put(People.NAME, name);
Uri newPerson = People.createPersonInMyContactsGroup(cr, values);
if (newPerson != null) {
    for (i=0; i<phone.length; i++) {
        Log.i("Phone",""+phone[i]);
        values.clear();
        Uri mobilesUri = Uri.withAppendedPath(newPerson,People.Phones.CONTENT_DIRECTORY);
        values.put(People.Phones.NUMBER,phone[i]);
        values.put(People.Phones.TYPE,People.Phones.TYPE_MOBILE);
        Uri phonesUpdate = cr.insert(mobilesUri, values);
    }
    for (i=0; i<email.length; i++) {
        Log.i("Email",""+email[i]);
        values.clear();
        Uri emailUri = Uri.withAppendedPath(newPerson,People.ContactMethods.CONTENT_DIRECTORY);
        values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);
        values.put(People.ContactMethods.TYPE,People.ContactMethods.TYPE_HOME);
        values.put(People.ContactMethods.DATA,email[i]);
        Uri emailUpdate = cr.insert(emailUri, values);
    }
}

中收到错误:

values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);

我在这一行

错误:找不到符号

编辑:我忘了提及我使用 Xcode/Ant 和修订版 8 (2.2 (Froyo))。

I'm trying to insert a new contact into the Androids contact list. Adding a name and phone numbers works fine, but adding an email address doesn't work. My code:

//name is a string
//phone and email are string arrays
ContentValues values = new ContentValues();
values.put(People.NAME, name);
Uri newPerson = People.createPersonInMyContactsGroup(cr, values);
if (newPerson != null) {
    for (i=0; i<phone.length; i++) {
        Log.i("Phone",""+phone[i]);
        values.clear();
        Uri mobilesUri = Uri.withAppendedPath(newPerson,People.Phones.CONTENT_DIRECTORY);
        values.put(People.Phones.NUMBER,phone[i]);
        values.put(People.Phones.TYPE,People.Phones.TYPE_MOBILE);
        Uri phonesUpdate = cr.insert(mobilesUri, values);
    }
    for (i=0; i<email.length; i++) {
        Log.i("Email",""+email[i]);
        values.clear();
        Uri emailUri = Uri.withAppendedPath(newPerson,People.ContactMethods.CONTENT_DIRECTORY);
        values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);
        values.put(People.ContactMethods.TYPE,People.ContactMethods.TYPE_HOME);
        values.put(People.ContactMethods.DATA,email[i]);
        Uri emailUpdate = cr.insert(emailUri, values);
    }
}

I get an error in this line:

values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);

of

error: cannot find symbol

Edit: I forgot to mention I use Xcode/Ant and revision 8 (2.2 (Froyo)).

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

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

发布评论

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

评论(2

游魂 2024-09-21 12:37:32

这对我有用:

    values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);

我从隐藏得很好的地方得到的(至少对于联系编程信息):
developer.android.com:内容提供程序:修改提供程序中的数据< /a>

This works for me:

    values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);

which I got from the well-hidden (at least for Contact programming info):
developer.android.com: Content Providers: Modifying data in a provider

痴者 2024-09-21 12:37:32

您可以从此示例中获得一些帮助: Android 开发者 - ContactOperations

You may get some help from this example: Android Developers - ContactOperations.

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