我可以在修改联系人时捕获该事件。但我想抓住修改后的联系方式,如CONTACT_ID,姓名等......请你能帮助我做到这一点。我的代码如下。
public class TestContentObserver extends Activity {
int contactCount = 0;
final String[] projection = new String[] { RawContacts.CONTACT_ID, RawContacts.DELETED };
Cursor curval;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
curval = getContentResolver().query(RawContacts.CONTENT_URI, projection, null, null, null);
contactCount = curval.getCount();
curval.registerContentObserver(new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
getChangedContactDetails();
}
@Override
public boolean deliverSelfNotifications() {
return true;
}
});
}
public void getChangedContactDetails(){
// how can I catch the affected contact details
}
}
答案 0 :(得分:-1)
查看:http://developer.android.com/resources/articles/contacts.html,“查找URI”部分
注册ContentObserver时,您只需注册一个直接指向您感兴趣的联系人的URI。然后您的观察者只会在您的有趣联系人被修改时收到通知。
Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
getContentResolver().registerContentObserver(lookupUri, false, new ContentObserver(){});
查找键对每条记录都是唯一的