如何在不删除已存储数据的情况下更新联系人?
我正在尝试做一个同步适配器来将我的联系人与网络存储同步。 当我向该服务器询问服务器端的任何联系人更新时,我会得到所有添加/更改的新信息的列表。要更新它们,我使用此处描述的首选
方法问题是,当我创建一个 ContactOperations.newUpdate()
并为其提供从网络服务器获得的所有新的/更改的信息,然后将其应用到ContactsContract.AUTHORITY
手机上已存储的所有信息都被删除了?!?
我举一个例子来阐明思路:
我的手机上保存了一个联系人,名叫:John 'Dady' Doe。现在 SyncAdapter 被系统调用,他向服务器请求任何联系人更改,服务器说,该联系人的姓氏现在是“Jones”。有了这些信息,我构建了一个新的 ContactProviderOperation.newUpdate()
并通过 .withValue()
提供它并应用它。但 Android 真正做的是:它刷新所有其他列,现在我的联系人名为“Jones”(givenName 和 middleName 缺失 -.-)。
有什么办法可以阻止Android这样做吗?我可以传递任何参数,例如 CALLER_IS_SYNCADAPTER
吗?或者我是否需要制定自己的解决方法(希望不需要),例如首先读取数据记录,应用更新,然后将其应用到 ContactsContract.AUTHORITY
?
任何提示真的很感激!
/edit: 我通过查看 SyncAdapterExample 做了进一步的研究,特别是在“更新联系人”部分,但我所看到的有点让我震惊:Google 实际上确实先读取联系人,然后应用从服务器更新并将其重新应用到 ContactsContract.AUTHORITY
。但他们只处理名字和姓氏、一封电子邮件和两部电话(普通电话和移动电话)。就我而言,我不想处理所有联系信息,因此做这样的解决方法是不可行的,除非没有其他方法,我希望不会。希望有人能引导我朝正确的方向前进。
I'm trying to do a sync adapter to sync my contacts with an webstorage.
When I ask this server for any contactupdates on the server-side I get a list of all the new informations added/changed. To update them I'm using the preferred method described here
My problem is that when I make a ContactOperations.newUpdate()
and feed it with all the new/changed informations I got from the webserver and then apply it to the ContactsContract.AUTHORITY
all the informations already stored on the phone are erased?!?
I make an example to make thinks clear:
I have an contact saved on my phone named: John 'Dady' Doe. Now the SyncAdapter ist invoked by the system, he ask the server for any contactchanges and the server says, that the familyname of this contact now is "Jones". With that information I construct a new ContactProviderOperation.newUpdate()
and feed it via .withValue()
and apply it. But what Android really does is: It flushes all othere columns and now my contact is named "Jones" (givenName and middleName missing -.-).
Is there any way to prevent Android from doing so? Can I pass any parameter like the CALLER_IS_SYNCADAPTER
? Or do I need to make my own workaround (hopefully not), like reading the data record first, apply the updates and then apply it to the ContactsContract.AUTHORITY
?
Any hint is really appreciated!
/edit: I did further studies by looking at the SyncAdapterExample, especially at the "update a contact"-part, but what I saw kinda shocked me: Google actually does read the contact first, then apply the updates from the server and reapply it to the ContactsContract.AUTHORITY
. But they only handle first- and lastname, one email and two phones (normal and mobile). In my case I wan't to handle ALL contactinformations, so it's not feasible to do such a workaround, except there is no other way, which I hope not. Hopefully someone can head me in the right direction for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完全是我的错:/
Android 做的一切都是正确的,我只是像这个家伙一样失败了 .. 。
Totally my fault :/
Android is doing everything right, I just failed as hard as this guy ...