0

I am importing contacts from csv file. i have tried importing using applybatch but it is taking too much time.So i have used bulkinsert method to insert contacts.But Contacts are not created.Below is the code.

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();}    
}

Any suggestions are highly appreciated.

B770
  • 1,272
  • 3
  • 17
  • 34
hemanth kumar
  • 3,068
  • 10
  • 41
  • 64

0 Answers0