どの連絡先がw / registerContentobServerを変更するかを判断できますか?

StackOverflow https://stackoverflow.com/questions/5020276

質問

registerContentobServer、またはその他のメソッドを使用しているときにどの連絡先が変更されたかを判断する簡単な方法があるかどうかを判断しようとしていますか?データベースが変更されたときにわかりますが、更新/変更が発生するたびにすべてのレコードを確認したいわかりません。

基本的に連絡先のリストがある場合、手動方式(すなわち、連絡先の電話番号を変更したり、新しい連絡先を追加したりする)または自動(ActiveSync Photoが追加され、変更されたもの)を介して更新されます。何かが変更されたことを知りたいのですが、b)データがいくつかのデータが変わったのかを知っています。

私は自分の写真をリモートサービスから一致させることができるかもしれない特定のユーザーを探しています。より多くの情報がユーザーアカウントに追加された場合は、それが試合に提供するかどうかを確認するためにそれを調べることができるようになりたいです。私はそれをスケジュールしたくないが、更新後にそれをやりたいのですが。

クリス

役に立ちましたか?

解決

I'm not sure which Uri you are currently registering for updates, but when you register your ContentObserver, can't you just register an individual Uri that points directly to the contact you are interested in? Then your observer will only get notified when your interesting contact is modified. The section in the SDK Documentation title "Lookup URI" talks more about this:

http://developer.android.com/resources/articles/contacts.html

The lookup key is unique to each record (row), so I would imagine doing something like this is what you are after?

Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
getContentResolver().registerContentObserver(lookupUri, false, myObserver);

And do that for each individual contact in your list.

For Added Contacts

The best way that I can see to do this is to re-query a cursor to the Contacts table each time the ContentObserver changes (re-query is fast, even if you're doing it often with lots of data), and maintain the highest known CONTACT_ID value. Whenever the cursor contains an ID beyond what you have stored, it was just added.

Also, if you haven't seen this conversation yet, it might be a good read. Dianne seems pretty adament that they keep specifics of content changes out of ContentObserver

Cheers.

他のヒント

Since this question was answered, there is a new callback method available in the ContentObserver class that has the uri of the changed content: http://developer.android.com/reference/android/database/ContentObserver.html#onChange(boolean, android.net.Uri)

This is available starting with the Android API Level 16

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top