Reputation: 904
Using this line of code:
Intent addContact = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
addContact.putExtra(ContactsContract.Intents.Insert.PHONE,"09876543210");
startActivity(addContact);
I was able to launch the Android's insert contact activity with a default contact number on it.
Now, using the defined intent above, how can I construct a startActivityForResult
so that I can get the inputted contact details (First name, Last Name etc.)?
Upvotes: 0
Views: 205
Reputation: 1681
Why start activity for result..? From your question I am getting that you want to create application which takes contact details from user and adds it as news contact to the contact list. You can achieve this using following code...
Intent intent = new Intent(Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
private EditText mEmailAddress = (EditText) findViewById(R.id.email);
private EditText mPhoneNumber = (EditText) findViewById(R.id.phone);
intent.putExtra(Intents.Insert.EMAIL, mEmailAddress.getText())
.putExtra(Intents.Insert.EMAIL_TYPE, CommonDataKinds.Email.TYPE_WORK)
.putExtra(Intents.Insert.PHONE, mPhoneNumber.getText())
.putExtra(Intents.Insert.PHONE_TYPE, Phone.TYPE_WORK);
Once you've created the Intent, send it by calling startActivity().
startActivity(intent);
See this link and this link for more options.
Upvotes: 2