but in LOGCAT i am getting the error
- Code: Select all
08-24 18:16:44.833: ERROR/ContentProviderOperation(152): mType: 1, mUri: content://com.android.contacts/data, mSelection: null, mExpectedCount: null, mYieldAllowed: false, mValues: data1=xzzsf mimetype=vnd.android.cursor.item/name, mValuesBackReferences: raw_contact_id=0, mSelectionArgsBackReferences: null
[color=#BF0040]08-24 18:16:44.863: ERROR/JavaBinder(152): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
08-24 18:16:44.863: ERROR/JavaBinder(152): java.lang.ArrayIndexOutOfBoundsException: asked for back ref 0 but there are only 0 back refs[/color]
can anyone please spot what is going worng?
my code to add contact is
- Code: Select all
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
.withValue(ContactsContract.CommonDataKinds.Email.TYPE, emailType)
.build());
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
Context ctx = getApplicationContext();
CharSequence txt = "Contact " + name +" added successfully";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(ctx, txt, duration);
toast.show();
} catch (Exception e) {
}
hey please help me out....... what is the simplest way to add a contact with code????? i have also attached the image of my error in LOGCAT.
PFA.
loads of thanks in advance

