Android 添加联系人电子邮件
我正在尝试将新联系人插入 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);
我在这一行
错误:找不到符号
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用:
我从隐藏得很好的地方得到的(至少对于联系编程信息):
developer.android.com:内容提供程序:修改提供程序中的数据< /a>
This works for me:
which I got from the well-hidden (at least for Contact programming info):
developer.android.com: Content Providers: Modifying data in a provider
您可以从此示例中获得一些帮助: Android 开发者 - ContactOperations。
You may get some help from this example: Android Developers - ContactOperations.