联系人不会插入到Android设备中

时间:2013-06-12 13:24:15

标签: android csv addressbook

我正在从csv文件导入联系人。我尝试使用applybatch进行导入但是花费了太多时间。所以我使用了bulkinsert方法来插入联系人。但是没有创建联系人。下面是代码。

for (int y = 0; y < firstcon.size(); y++) {
    if(isCancelled()){
            break;
    }else{
            operations = new ArrayList<ContentProviderOperation>();
            condition();
    if (newphns.contains(phonecon.get(y).trim())) {
            System.out.println("exists");
            count --;
    } else {
            System.out.println("creating");
            cvals = new ContentValues();
            cvals.put(Data.RAW_CONTACT_ID,"0");
            cvals.put(Data.MIMETYPE,StructuredName.CONTENT_ITEM_TYPE);
    if (lastcon.get(y).equals("nothing")) {
            cvals.put(StructuredName.GIVEN_NAME,firstcon.get(y));                   
            cvals.put(StructuredName.FAMILY_NAME, "");
    }else if (firstcon.get(y).equals("nothing")) {
            cvals.put(StructuredName.GIVEN_NAME,"");                        
            cvals.put(StructuredName.FAMILY_NAME, lastcon.get(y));
    }else{
                cvals.put(StructuredName.GIVEN_NAME,firstcon.get(y));                       
                cvals.put(StructuredName.FAMILY_NAME, lastcon.get(y));
    }

    cvals.put(ContactsContract.CommonDataKinds.Phone.NUMBER,phonecon.get(y));
    cvals.put(ContactsContract.CommonDataKinds.Phone.TYPE,ContactsContract.CommonDataKinds.Phone.TYPE_HOME);
    values[y] = cvals;
    }
}

try {
     getContentResolver().bulkInsert(Data.CONTENT_URI, values);//applyBatch(ContactsContract.AUTHORITY, operations);
} catch (Exception e) {e.printStackTrace();}    
}

非常感谢任何建议。

0 个答案:

没有答案