Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add contact intent doesn't return data onActivityResult under ICS

I want my application to prompt the user to create a new contact, through the standard Contacts interface on Android. Then I want to be able to read the information back from the newly created contact.

My code is based on the "Adding A New Contact" from this site.

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, number);
startActivityForResult(intent, PICK_CONTACT);

and then

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Intent intent = new Intent(this, Foo.class);
    Uri uri = data.getData(); //I get nullpointer here on ICS
    intent.putExtra("contact", ContactAccessor.getInstance().loadContact(this, uri));
    startActivity(intent);
    finish();
}

This code runs fine on Android 2.2 and 2.3. It starts the contacts application and lets the user input stuff like name and email address and when they're done and hit "ok" or "save" or "whatever" it returns to my app and I can read the stuff they entered. On Android 4.0 (ICS) however it does not return back to my app, when the user is done creating the contact. And when I exit the contact view (through the back button) it does not include any intent with the contact information.

What intent should I use to get the same behavior on ICS?

like image 919
getekha Avatar asked Dec 21 '11 22:12

getekha


1 Answers

For Android 4.0.3 and up, you need to provide a new intent extra:

public static final String INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED = "finishActivityOnSaveCompleted";

intent.putExtra(INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);

I don't have a solution for Android 4.0 to 4.0.2.

Anyone?

like image 181
OferR Avatar answered Sep 22 '22 05:09

OferR