
中间名
,后名),多个住宅电话(如住宅:8988888,第二个也是住宅:8988888),多个手机等等。。。。,点击这个联系人时,这些信息都能显示,但是编辑的时候就出错!我想实现的思想是:在我恢复联系人时,当某个联系人信息已经存在,我就不恢复,如果不存在,我就恢复,往数据库里插入信息就可以了!
参考下面:ArrayList<ContentProviderOperation>ops = new ArrayList<ContentProviderOperation>()
ArrayList<VCardEntry>list = params[0]
Iterator<VCardEntry>it = null
if (list != null) {
it = list.iterator()
}
Logger.v(TAG,"--->doInBackground it:"+it)
int rawContactInsertIndex = 0
while(it!= null &&it.hasNext()) {
VCardEntry mv = it.next()
rawContactInsertIndex = ops.size()// 有了它才能给真正的实现批量添加
Logger.v(TAG,"--->>>>>>>name:"+mv.getDisplayName())
Logger.v(TAG,"--->>>>>>>getPhoneList:"+mv.getPhoneList())
if (mv.getPhoneList() != null) {
ops.add(ContentProviderOperation
.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, ACCOUNT_NAME)
.withValue(RawContacts.ACCOUNT_NAME, ACCOUNT_TYPE)
.withYieldAllowed(true).build())
// add name
ops.add(ContentProviderOperation
.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, mv.getDisplayName())
.withYieldAllowed(true).build())
// add number
for(VCardEntry.PhoneData phone : mv.getPhoneList()) {
Logger.v(TAG,"--->>>>>>>number:"+phone.getNumber())
ops.add(ContentProviderOperation
.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, phone.getNumber())
.withValue(Phone.TYPE, Phone.TYPE_MOBILE)
.withValue(Phone.LABEL, "")
.withYieldAllowed(true).build())
}
}
}
ContentProviderResult[] results = null
if (ops != null) {
try {
results = mContext.getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, ops)
} catch (RemoteException e) {
Logger.e(TAG,String.format("%s: %s", e.toString(), e.getMessage()))
} catch (OperationApplicationException e) {
Logger.e(TAG,String.format("%s: %s", e.toString(), e.getMessage()))
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)