delete contact details

Put your problem here if it does not fit any of the other categories.

delete contact details

Postby saif_zeenwala » Tue Nov 03, 2009 12:01 pm

hi guys

I am newbie to android

Actually i want to delete contacts details from phone

I want to delete all information pertaining to contact list
like name, phone number, emailID, photo, multiple numbers if have etc

I had written some code but able to delete only numbers, not other details

I am pasting here my code
Please let me know where i am wrong


// An array specifying which columns to return.
String[] projection = new String[] {
People._ID,
People.NAME,
People.NUMBER,
};

// Get the base URI for People table in Contacts content provider.
// which is: content://contacts/people/
Uri contactUri = People.CONTENT_URI;

// Best way to retrieve a query; returns a managed query.
Cursor peopleCursor = managedQuery (contactUri,
projection, //Which columns to return.
null, // WHERE clause--we won't specify.
null, // Selection Args??
People.DEFAULT_SORT_ORDER); // Order-by name

// go to the beginning of the list
peopleCursor.moveToFirst();


ArrayList<String> idsToDelete = new ArrayList<String>();
if(peopleCursor.moveToFirst()) {
final int colId = peopleCursor.getColumnIndex(People.Phones._ID);
final int colNumber = peopleCursor.getColumnIndex(People.Phones.NUMBER);
final int colName = peopleCursor.getColumnIndex(People.Phones.NAME);
do {
String id = peopleCursor.getString(colId);
String number = peopleCursor.getString(colNumber);
String name = peopleCursor.getString(colName);
Log.i("DEBUG","id::::"+ id + ":::::"+ number+ ":::::::"+ name);
idsToDelete.add(id);
} while (peopleCursor.moveToNext());

Log.i("DEBUG","after while loop.........");
Uri.Builder builder = contactUri.buildUpon();
Uri phoneNumbersUri = builder.build();

Log.i("DEBUG","AFTER some Lines.....");

for (String id : idsToDelete) {
Log.i("DEBUG","id:::::::"+ id);
builder.encodedPath(People.Phones.CONTENT_DIRECTORY + "/" + id);
phoneNumbersUri = builder.build();
getContentResolver().delete(phoneNumbersUri, "1 = 1", null);
}
}

Plz suggest.
saif_zeenwala
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Nov 02, 2009 7:40 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests