android - how to detect new contacts added to the contact database -


how detect new contacts added contact database

i find lot of code on internet not work or contain errors.....

is there idea not code detect new contacts add

i know questions difficult, idea or simple answer ::)

i tested code returns errors

contentresolver cr = ctx.getcontentresolver();      string[] projection = new string[] { contactscontract.contacts._id, contactscontract.contacts.display_name };      cursor cur = cr.query(contactscontract.contacts.content_uri, projection, null, null,             contactscontract.contacts.display_name + " collate localized asc");      if (cur.getcount() > 0) {         while (cur.movetonext()) {             toast.maketext(this,cur.getstring(cur.getcolumnindex(contactscontract.data._id)), toast.length_short).show();             toast.maketext(this,cur.getstring(cur.getcolumnindex(contactscontract.data.display_name)), toast.length_short).show();           //  system.out.println(cur.getstring(cur.getcolumnindex(contactscontract.data._id)));         //  system.out.println(cur.getstring(cur.getcolumnindex(contactscontract.data.display_name)));                   cursor pcur = cr.query(contactscontract.commondatakinds.phone.content_uri,                  null, contactscontract.commondatakinds.phone.contact_id +" = ?",                  new string[]{ c.getid() }, null);          while (pcur.movetonext()) {              toast.maketext(this, "start!", toast.length_short).show();             system.out.println(.add(pcur.getstring(pcur.getcolumnindex(contactscontract.commondatakinds.phone.number)));         }          pcur.close();              cursor emailcur = cr.query(contactscontract.commondatakinds.email.content_uri,                      null, contactscontract.commondatakinds.email.contact_id + " = ?",                      new string[]{ c.getid() }, null);               while (emailcur.movetonext()) {              system.out.println((emailcur.getstring(             emailcur.getcolumnindex(contactscontract.commondatakinds.email.data)));         }         }     }     cur.close(); 

first u need register receiver in main activity--

getcontentresolver().registercontentobserver(contactscontract.contacts.content_uri, true,new mycontentobserver());

after that

public class mycontentobserver extends contentobserver {      public mycontentobserver() {         super(null);     }      @override     public void onchange(boolean selfchange) {         super.onchange(selfchange);         log.d("onchange1", "~~~~~~" + selfchange);          //getapplicationcontext().startservice(new intent(mainactivity.this, sendcontactservice.class));     }      @override     public boolean deliverselfnotifications() {         log.d("deliverselfnotifications", "~~~~~~fg");         return true;     } } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -