My code is as following
Permission
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
And caller Activity code is
Intent addNewContact = new Intent(Intent.ACTION_INSERT);
addNewContact.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(addNewContact, ADD_NEW_CONTACT); // ADD_NEW_CONTACT = 2 for my specific purpose
And onActivityResult of caller Activity as
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("OnActivityResult Test ", "Request code : " + requestCode
+ " " + " ResultCode : " + resultCode);
switch(requestCode) {
case 2:
if (resultCode == Activity.RESULT_OK) {
// code to Update my list view
}
}
}
My list view gets update on emulator and device (I checked with samsung galuxy) also other than Droid-X, so result doesn’t reflect on list if I am using Droid-X.
When I read Log cat msg of Droid-X I saw resultCode is always 0 (ZERO), even if I am adding new contact.
I know that the problem with Droid-X, motoblur is that (per moto’s website) the blur contacts API is based off of the old Contacts API found in Android 1.x, and not the new 2.x ContactsContract API. It’s possible that HTC does the same.
Ref :
Created contacts not showing up on HTC Evo
New contacts created using ContactsContract do not appear in Contacts app
In your case you didn’t get result code as -1, when you are adding new contact. So better way don’t do any task (if you doing when contact is added) in
onActivityResult. Extend ContentObserver class that will receive call backs for changes to content, and you can do your task.Ref :
1. How to implement an Android ContentObserver
And here is a sample example
Hope this will help.
Update : Contacts 2.x API works on MOTOBLUR phones running Gingerbread (Android 2.3) or higher. My Droid X is running Moto’s new Gingerbread, and I’m quite pleased that this now works.