Adding Contacts Android 2.3 rawContactId

578 Views Asked by At

I'm new to java and developing apps, I can't figure out how to add a contact. I'm taking right from the android development website:

ContentValues values = new ContentValues();  
 values.put(Data.RAW_CONTACT_ID, rawContactId);  
 values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);  
 values.put(Phone.NUMBER, "1-800-GOOG-411");  
 values.put(Phone.TYPE, Phone.TYPE_CUSTOM);  
 values.put(Phone.LABEL, "free directory assistance");  
 Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);

My question is: what do you put in the place of rawContactId? Is it supposed to be the name of the contact? I want to move on to the newer way to add contacts below, but I can't even get the "traditional" way to work. Help?

ArrayList<ContentProviderOperation> ops =  new ArrayList<>();  

ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
          .withValue(Data.RAW_CONTACT_ID, rawContactId)  
          .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)  
          .withValue(Phone.NUMBER, "1-800-GOOG-411")  
          .withValue(Phone.TYPE, Phone.TYPE_CUSTOM)  
          .withValue(Phone.LABEL, "free directory assistance")  
          .build());  
 getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
0

There are 0 best solutions below