I want contact number for my android application when any new contact added or contact is edited / deleted from android in built app.
I have tried below code.
public class MainActivity extends Activity{
MyContentObserver contentObserver = new MyContentObserver();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.getApplicationContext().getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contentObserver);
}
private class MyContentObserver extends ContentObserver {
public MyContentObserver() {
super(null);
}
@SuppressLint("NewApi")
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
Log.e("contact ", "Changed or added");
Log.e("URI",uri.toString());
}
}
}
I can see log when contact is added / edited / deleted. But i have got stuck to get a particular contact number which is added / edited / deleted from android inbuilt application.
what should i write in onChange() to get contact number?
My main requirement is i do not want to read all contact from android phone. I just want a single contact number which is newly added / edited / deleted.
Anyone know about this? please guide me.