我正在尝试在Androids联系人列表中插入新的联系人。添加姓名和电话号码工作正常,但添加电子邮件地址不起作用。我的代码:
//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);
的
错误:找不到符号
答案 0 :(得分:2)
这对我有用:
values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);
我从隐藏得很好(至少对于联系编程信息): developer.android.com: Content Providers: Modifying data in a provider
答案 1 :(得分:0)
您可以从此示例中获得一些帮助:Android Developers - ContactOperations。