如何以编程方式在 newInsert 到地址簿后获取最后插入的 RawContacts ID?
我成功地将联系人插入地址簿,我需要在我的应用程序中保存联系人的引用。我认为保存引用的最佳方法是获取 RawContacts ID 本身。
有没有办法让我在插入新联系人后直接从通讯录中取回ID?或者我是否必须取出所有记录并将其与我的数据进行比较才能获取 RawContacts ID?
我使用以下代码进行插入:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null)
.withValue(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_DISABLED)
.build());
我感谢任何输入,无论是解决方法还是来自 API。谢谢!
I succeeded in inserting contacts into the address book and I need to save a reference of the contact in my app. I figured that the best way to save the reference is to get the RawContacts ID itself.
Is there a way for me to directly get the ID back from the address book right after the insertion of the the new contact? Or do I have to get every records out and compare them with my data to get the RawContacts ID?
I do my insert using this code:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null)
.withValue(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_DISABLED)
.build());
I appreciate any inputs, be it a workaround or from the API. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用从 getContentResolver() 返回的信息(无论如何您都必须调用该信息才能将操作添加到数据库中)。
getContentResolver() 需要有一个 try,catch 环境。
you can use the information returned from getContentResolver() (which you anyways have to call in order to add ops to the DB.
getContentResolver() needs to have a try,catch environment.