android - Contact API problem with save datas Options -
i'm facing basic problem didn't find tutorial in order me...
i'm writing application sort of backup contact options. want applications works android phones since 1.5 2.2
so write 2 implementation of contactapi, 1 1.5, 1.6 , other new api version.
here list of problem i'm facing with.
with new api, nothing. works fine, backing contacts works well.
but older api i'm not able backing datas :
- email datas (able read, not able save)
- im datas (able read, not able save)
- notes (able read first note, if many notes, lost datas, same things backup)
here code i'm using :
=======email=======
private arraylist<email> getemailaddresses(string id) { arraylist<email> emails = new arraylist<email>(); cursor emailcur = this.contentresolver.query(contacts.contactmethods.content_email_uri, null, contacts.contactmethods.person_id + " = ?", new string[] { id }, null); email email = null; while (emailcur.movetonext()) { // allow several email addresses email = new email(); email.setdata(emailcur.getstring(emailcur.getcolumnindex(contacts.contactme thods.data))); email.settype(emailcur.getint(emailcur.getcolumnindex(contacts.contactmetho ds.type))); email.setlabel(emailcur.getstring(emailcur.getcolumnindex(contacts.peopleco lumns.name))); emails.add(email); } emailcur.close(); return emails; } private void saveemailaddresses(contenturis contacturi, list<email> emaillist, string id) { if (emaillist != null && emaillist.size() > 0) { contentvalues values = null; contentvalues[] valuearray = new contentvalues[emaillist.size()]; int = 0; (email email : emaillist) { values = new contentvalues(); values.put(contacts.contactmethods.person_id, id); // values.put(contacts.contactmethods.kind, contacts.kind_email); // values.put(contacts.contactmethods.data, email.getdata()); // values.put(contacts.contactmethods.type, email.gettype()); // values.put(contacts.peoplecolumns.name, email.getlabel()); // valuearray[i] = values; i++; } contentresolver.bulkinsert(contacts.contactmethods.content_email_uri, valuearray); } }
======== im adress=============
private arraylist<im> getim(cursor cur, string id) { arraylist<im> imlist = new arraylist<im>(); string = contacts.contactmethods.person_id + " = ? , " + contacts.contactmethods.kind + " = ?"; string[] whereparameters = new string[] { id, string.valueof(contacts.kind_im) }; cursor imcur = this.contentresolver.query(contacts.contactmethods.content_uri, null, where, whereparameters, null); im im = null; while (imcur.movetonext()) { try { string imname = imcur.getstring(imcur.getcolumnindex(contacts.contactmethodscolumns.data)); im = new im(); im.setname(imname); im.settype(imcur.getint(imcur.getcolumnindex(contacts.contactmethodscolumns .type))); im.setprotocol(cur.getstring(imcur.getcolumnindex(contacts.contactmethods.a ux_data))); imlist.add(im); } catch (exception e) { log.e(where, "error im : ", e); } } imcur.close(); return imlist; } private void saveim(list<im> imlist, string id) { if (imlist != null && imlist.size() > 0) { contentvalues values = null; contentvalues[] valuearray = new contentvalues[imlist.size()]; int = 0; (im im : imlist) { values = new contentvalues(); values.put(contacts.contactmethods.person_id, id); // values.put(contacts.contactmethods.kind, contacts.kind_im); // values.put(contacts.contactmethodscolumns.data, im.getname()); // values.put(contacts.contactmethods.aux_data, contactmethods.encodecustomimprotocol(im.getprotocol())); // values.put(contacts.contactmethodscolumns.type, im.gettype()); // valuearray[i] = values; i++; } contentresolver.bulkinsert(contacts.contactmethods.content_uri, valuearray); } }
==========notes =======
i have no idea how notes ?
can me ?
public static hashmap parse(string xml, string tag, arraylist<string> nodeslist) { hashmap v = new hashmap(); try { documentbuilderfactory dbf = documentbuilderfactory.newinstance(); documentbuilder db = dbf.newdocumentbuilder(); inputsource = new inputsource(); is.setcharacterstream(new stringreader(xml)); document doc = db.parse(is); doc.getdocumentelement().normalize(); nodelist nodelst = doc.getelementsbytagname(tag); nodecount = nodelst.getlength(); (int s = 0; s < nodecount; s++) { node fstnode = nodelst.item(s); if (fstnode.getnodetype() == node.element_node) { element fstelmnt = (element) fstnode; for(string nodename : nodeslist) { nodelist fstnmelmntlst = fstelmnt.getelementsbytagname(nodename); element fstnmelmnt = (element) fstnmelmntlst.item(0); nodelist fstnm = fstnmelmnt.getchildnodes(); try { string nodevalue = ((node) fstnm.item(0)).getnodevalue().tostring().trim(); if(nodevalue !=null ) v.put(nodename + s, nodevalue); } catch(exception e) { v.put(nodename + s, ""); } } } } } catch (exception e) { //e.printstacktrace(); } return v; }
Comments
Post a Comment