Android - Trouble deleting only contacts with a specified note -


i working on project creates random contacts having trouble implementing deletion capability. have marked each generated contact note through

        ops.add(contentprovideroperation             .newinsert(contactscontract.data.content_uri)             .withvaluebackreference(data.raw_contact_id,                     rawcontactinsertindex)             .withvalue(data.mimetype, note.content_item_type)             .withvalue(note.note, note)             .build()); 

now delete contacts need use similar have found here

uri contacturi = uri.withappendedpath(phonelookup.content_filter_uri,                            uri.encode(phonenumber));        cursor cur = ctx.getcontentresolver().query(contacturi, null, null,                        null, null);        try {            if (cur.movetofirst()) {                {                   string lookupkey =                      cur.getstring(cur.getcolumnindex(contactscontract.contacts.lookup_key));                   uri uri = uri.withappendedpath(                                  contactscontract.contacts.content_lookup_uri,                                  lookupkey);                   ctx.getcontentresolver().delete(uri, null, null);                } while (cur.movetonext());            }         } catch (exception e) {                system.out.println(e.getstacktrace());        }        return false; } 

i believe difference between code above , searching 1 above uses phone number delete contact purposes need delete note field of contact.

fixed problem..i new java , tried comparing strings using '==' instead of stringobject.equals().

here little function delete contacts based on string in case needs that.

public void deletecontacts(string contactnote){     contentresolver cr = getcontentresolver();     cursor cur = cr.query(contactscontract.contacts.content_uri,             null, null, null, null);     string note;     while (cur.movetonext()) {         note = "";         try{              string lookupkey = cur.getstring(cur.getcolumnindex(contactscontract.contacts.lookup_key));             string notewhere = contactscontract.contacts.lookup_key + " = ? , " + contactscontract.data.mimetype + " = ?";             string[] notewhereparams = new string[]{lookupkey,                     contactscontract.commondatakinds.note.content_item_type};             cursor notecur = cr.query(contactscontract.data.content_uri, null, notewhere, notewhereparams, null);             if (notecur.movetofirst()) {                 note = notecur.getstring(notecur.getcolumnindex(contactscontract.commondatakinds.note.note));                 if(note.equals(contactnote)) {                         uri uri = uri.withappendedpath(contactscontract.contacts.content_lookup_uri, lookupkey);                         cr.delete(uri, null, null);                 }             }             notecur.close();         }         catch(exception e)         {             system.out.println(e.getstacktrace());         }     }     cur.close(); } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -