views:

542

answers:

1

Hi,

I have a requirement wherein I need a list of all the contacts that are edited/changed.

As per the Android documentation,

_SYNC_DIRTY

will be set every time a contact is edited. But, there seems to be a bug in this, which makes this always set to 1 (no matter what), even is we explicitly set it to 0.

So, I was wondering if I can create a SQLite TRIGGER on the contacts database. Such that, everytime a contact is edited, the edited contact id is populated into a different table which I can read later from my application.

I tried this...

CREATE TRIGGER IF NOT EXISTS updated_contacts UPDATE ON 'contacts.db'.phones
   BEGIN
   INSERT INTO updated_table SET updated_id=old.person;
   END;

But a few problems here...

1) 'phones' is a table in the contacts database. but, I am not sure about the name of the contacts database (here I have assumed it to be 'contacts.db').

2) updated_table is a table on a different database 'mydatabase.db' that I have created from my application. and, I am not sure if I can set TRIGGERS across different databases.

All this in Android 1.6

Also, I am not sure about the permission to access native contacts database on Android.

Is there any other way of achieving this.

Any info regarding this would be of great help.

Thanks.

+3  A: 

So, I was wondering if I can create a SQLite TRIGGER on the contacts database.

You do not have access to the underlying SQLite database.

You can try using registerContentObserver() to be notified as the contacts are changed.

CommonsWare
Thanks a ton for the respose. I did look into some document regarding this api. It is definitely a way of achieving what I want.But, If I use this api to monitor the changes done on the contacts database, I will have to keep my app always running in the background, a little too expensive I guess... So, I have thought of a workaround.I will store the hash of the contacts. And, every time I launch my app, it will compare the hash of contacts existing on the device with the hash stored earlier. This will give me the list of all the contacts edited between subsequent launches.Any other ways?
Sunieal
That will get rather expensive for large #s of contacts.
CommonsWare