保存android联系后获取联系人ID

保存android联系后获取联系人ID,第1张

概述我通过此代码保存联系人 ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ... int rawContactInsertIndex = ops.size(); ops.add(ContentProviderOperation.newInsert(Raw 我通过此代码保存联系人
ArrayList<ContentProvIDerOperation> ops =          new ArrayList<ContentProvIDerOperation>(); ... int rawContactInsertIndex = ops.size(); ops.add(ContentProvIDerOperation.newInsert(RawContacts.CONTENT_URI)          .withValue(RawContacts.ACCOUNT_TYPE,accountType)          .withValue(RawContacts.ACCOUNT_name,accountname)          .build()); ops.add(ContentProvIDerOperation.newInsert(Data.CONTENT_URI)          .withValueBackReference(Data.RAW_CONTACT_ID,rawContactInsertIndex)          .withValue(Data.MIMETYPE,Structuredname.CONTENT_ITEM_TYPE)          .withValue(Structuredname.GIVEN_name,linkname1)          .withValue(Structuredname.FAMILY_name,linkname2)          .build()); getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);

保存联系人后,我需要获取_ID字段,以便我可以从联系人簿中获取该联系人以进行编辑.保存后如何获取ID?

提前致谢

解决方法
ContentProvIDerResult[] res = getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);Uri myContactUri = res[0].uri;int contactID = Integer.parseInt(myContactUri.getLastPathSegment());
总结

以上是内存溢出为你收集整理的保存android联系后获取联系人ID全部内容,希望文章能够帮你解决保存android联系后获取联系人ID所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1141003.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存