Any Listener for Added, Updated and Deleted contacts??

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

Any Listener for Added, Updated and Deleted contacts??

Postby Chitra » Sat Jun 19, 2010 8:39 am

Hi,

let me know any listener for added, updated and also deleted contacts from mobile??
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Bangalore

Top

Re: Any Listener for Added, Updated and Deleted contacts??

Postby padde » Sat Jun 19, 2010 9:38 am

What you are searching for is ContentObserver.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Re: Any Listener for Added, Updated and Deleted contacts??

Postby Chitra » Sun Jun 20, 2010 6:33 am

Hi padde,
I am trying to listen for any change in the contact database. But When I use 'EditContact' to change the contact database, My onChange function does not get called.

FYI,
ContentObserver contentObserver = new ContentObserver();
context.getContentResolver().registerContentObserver(People.CONTENT_URI, true, contentObserver);
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Bangalore

Re: Any Listener for Added, Updated and Deleted contacts??

Postby padde » Sun Jun 20, 2010 8:50 am

have you tried to watch Contacts.CONTENT_URI ?
And what version of android you are targeting / testing this ?

Starting with 2.0 the hole Contacts thingy changed.. maybe this is a problem here.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Re: Any Listener for Added, Updated and Deleted contacts??

Postby Chitra » Sun Jun 20, 2010 9:04 am

My targeting is on android latest version 2.2....

Next I want to try on Contacts.CONTENT_URI....

Thanks padde for your quick reply...
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Bangalore

Re: Any Listener for Added, Updated and Deleted contacts??

Postby padde » Sun Jun 20, 2010 11:42 am

Since version 2.0 it should be ContactsContract.Contacts.CONTENT_URI you should watch.. or
ContactsContract.RawContacts.CONTENT_URI. But its just a guess.. i never concerned myself
with the hole new contacts scheme, authority, accounts and that hole stuff.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Re: Any Listener for Added, Updated and Deleted contacts??

Postby Chitra » Mon Jun 28, 2010 12:33 pm

Hi...
I got listener for added, updated and deleted contacts...
Below i explained briefly,

//Content URI for contacts listener
public void startMonitoring() {
monitorStatus = false;
if (!monitorStatus) {
contentResolver.registerContentObserver( Contacts.People.CONTENT_URI,
true, contactsObserver);
Cursor curval = mainActivity.managedQuery(People.CONTENT_URI,
null, null, null, null);
if (curval != null && curval.getCount() > 0) {
contactCount = curval.getCount();
}
}
}


//Notification - Onchange
public void onChange(final boolean bSelfChange) {
super.onChange(bSelfChange);
Thread thread = new Thread() {
public void run(){
try {

/*** ID & Name ***/
Cursor cur = mainActivity.managedQuery(People.CONTENT_URI,
null, null, null, null);
int curCount = 0;
if (cur != null && cur.getCount() > 0) {
curCount = cur.getCount();
}

if ((curCount >= contactCount) || (curCount < contactCount)) {
contactCount = curCount;
cur.moveToLast();
do{
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Log.i("MyApp","===>>ID : " + id);
Log.i("MyApp","===>>Name : " + name);
}while (cur.moveToPrevious()) ;
}
}
catch (Exception e) {
Log.i("MyApp","Exception in Monitor.onChange - " + e.getMessage());
}
}
};
thread.start();
}
}


By using this code we can able to monitor contact ID, Contact name.. How to monitor remaining contact details i.e., phone number, email, address, etc., ??? Plz help me....
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Bangalore

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 12 guests