更新联系电子邮件地址时出现问题
我正在尝试使用此代码更新联系人电子邮件地址
String selectEmail = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" +
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE + "'";
String[] emailArgs = new String[]{Id};
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(selectEmail, emailArgs)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
.build());
我使用此代码获取“Id”
String[] returnVals = new String[] {ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
this.cur = this.cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
returnVals,
ContactsContract.CommonDataKinds.Phone.NUMBER + " = \"" + phoneNumber + "\"",
null,
null);
我的问题是
- 我是否使用正确的方法使用电话号码获取 Contact_ID 联系人
- 未正确更新,它正在更改电子邮件、姓名等所有字段和数量。我做错了什么吗?
需要帮助。
I am trying to update contact email address using this code
String selectEmail = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" +
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE + "'";
String[] emailArgs = new String[]{Id};
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(selectEmail, emailArgs)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
.build());
I am getting "Id" using this code
String[] returnVals = new String[] {ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
this.cur = this.cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
returnVals,
ContactsContract.CommonDataKinds.Phone.NUMBER + " = \"" + phoneNumber + "\"",
null,
null);
My questions are
- Am I using correct way for getting Contact_ID using the Phone number
- Contacts are not updating correctly, it is changing all fields like email, name and number. Am I doing something wrong?
Need help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在阅读此答案之前,请格式化您的代码...;)
您可以找到如何更新联系人的示例此处 以及一个进行号码查找的示例 此处。
祝你好运
汤姆
Please format your code, before reading this answer... ;)
You can find an example how to update contacts here and an example to do a number lookup here.
Good luck
Tom