user8182205
user8182205

Reputation: 31

How to save a contact in phone via intent? Or something using android studio?

I am working on a business card reader app for digitalizing purposes. I have successfully got the recognition result in the form of XML. I have also parsed that XML file and extracted out the fields such as name, email, mobile no.

How can I save this data in my phone contact via my app?

Upvotes: 2

Views: 4223

Answers (3)

Jéwôm'
Jéwôm'

Reputation: 3971

Create a new Intent :

Intent intent = new Intent(Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);

Put some Extras in your intent like EMAIL or PHONE_TYPE :

intent.putExtra(Intents.Insert.EMAIL, "[email protected]");
intent.putExtra(Intents.Insert.PHONE, "15417543010");

and don't forget at the end to start the Activity :

startActivity(intent);

Upvotes: 0

BhalchandraSW
BhalchandraSW

Reputation: 712

// Creates a new Intent to insert a contact
Intent intent = new Intent(Intents.Insert.ACTION);
// Sets the MIME type to match the Contacts Provider
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);

/*
 * Inserts new data into the Intent. This data is passed to the
 * contacts app's Insert screen
 */
// Inserts an email address
intent.putExtra(Intents.Insert.EMAIL, mEmailAddress.getText())
/*
 * In this example, sets the email type to be a work email.
 * You can set other email types as necessary.
 */
      .putExtra(Intents.Insert.EMAIL_TYPE, CommonDataKinds.Email.TYPE_WORK)
// Inserts a phone number
      .putExtra(Intents.Insert.PHONE, mPhoneNumber.getText())
/*
 * In this example, sets the phone type to be a work phone.
 * You can set other phone types as necessary.
 */
      .putExtra(Intents.Insert.PHONE_TYPE, Phone.TYPE_WORK);

Source: Insert a New Contact Using an Intent

Upvotes: 2

Nelson Wright
Nelson Wright

Reputation: 506

Have a look at the Contacts Provider.

Upvotes: 0

Related Questions