How to Launch the 'Add Contact' Activity in Android

How can I launch the 'Add Contact' activity in android

This post may help you out or at least point you in the right direction.

Hope this helps.

Update 05/11/2015:

Per the comments, check out vickey's answer below for the appropriate solution.

How to use intent to launch Add Contact activity?

Intent intent = new Intent(
ContactsContract.Intents.SHOW_OR_CREATE_CONTACT,
Uri.parse("tel:" + phoneNumber));
intent.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true);
startActivity(intent);

Launch Contacts Activity through Intent

You should add READ_CONTACT permission in AndroidManifest.

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, 10011);

How to launch contact detail activity of directory contact in android

This is tricky, but managed to get it working
You need to get the contact's LOOKUP_KEY, build a LookupUri from it, append the DIRECTORY_PARAM_KEY to the LookupUri, and put that in the intent's setData.

String name = "hello";
String directoryId = "5"

Uri uri = Contacts.CONTENT_FILTER_URI.buildUpon().appendPath(name).appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, directoryId).build();
String[] projection = new String[]{Contacts._ID, Contacts.DISPLAY_NAME, Contacts.LOOKUP_KEY};
Cursor cur = getContentResolver().query(uri, projection, null, null, null);
DatabaseUtils.dumpCursor(cur); // debug

// add some safety checks first obviously...
cur.moveToFirst();
String lookup = cur.getString(2);
Uri lookupUri = Contacts.getLookupUri(cur.getLong(0), lookup).buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, directoryId).build();

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(lookupUri);
startActivity(intent);

Insert a new contact intent

Finally found a solution, I'm sharing it with you.
That's only a fix for Android version above 4.0.3 and sup. It doesn't work on 4.0 to 4.0.2.

i = new Intent(Intent.ACTION_INSERT);
i.setType(Contacts.CONTENT_TYPE);
if (Integer.valueOf(Build.VERSION.SDK) > 14)
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, PICK_CONTACT_REQUEST);


Related Topics



Leave a reply



Submit