android - How to know if their is change in call log using contentOberser. -


i new android development. want monitor changes occurred in call log.my code fetching call history until last recent call log.when run app again fetches logs including newest 1 want latest changes. please guide me how can achieve contentoberser ? please help. code

private void conatctdetails()     {         stringbuffer sb = new stringbuffer();         cursor c1 = getcontentresolver().query(contactscontract.contacts.content_uri, null, null, null, contactscontract.contacts.display_name);         sb.append("contact details:");         try         {         while(c1.movetonext())           {               string id = c1.getstring(c1.getcolumnindex(contactscontract.contacts._id));               string name =c1.getstring(c1.getcolumnindex(contactscontract.contacts.display_name));               string timescontacted =c1.getstring(c1.getcolumnindex(contactscontract.contacts.times_contacted));               string lasttimecontacted =c1.getstring(c1.getcolumnindex(contactscontract.contacts.last_time_contacted));                string number="";              // string number =c1.getstring(c1.getcolumnindex(commondatakinds.phone.number));               if(id==null||name==null)                   continue;               cursor cur = getcontentresolver().query(commondatakinds.phone.content_uri, null, commondatakinds.phone.contact_id +" = ?", new string[]{id}, null);                 if(cur==null)                     continue;                 number = "";                 while(cur.movetonext())                 {                     number = cur.getstring(cur.getcolumnindex(commondatakinds.phone.number));                     sb.append("\n contact number:--"+number);                 }                sb.append("\n contact name:--"+name+"\n contact id:--"+id+"\n last time contacted:--"+lasttimecontacted+"\n total time contacted:--"+timescontacted);          sb.append("\n----------------------------");           }         //c1.close();          contact.settext(sb);      }     catch(exception e)     {      }                 {             c1.close();         }     } 

if there intent fired on incoming call app respond using broadcastreceiver , create intentfilter in manifest.

or query provider when app launches...

action_phone_state_changed telephonymanager intent can listen , check if telephonymanager.call_state_ringing.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -