1

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?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
user8182205
  • 21
  • 1
  • 2
  • 1
    Use this https://developer.android.com/reference/android/provider/ContactsContract.Data.html and https://stackoverflow.com/questions/4744187/how-to-add-new-contacts-in-android – Mayur Raval Jun 19 '17 at 09:30

3 Answers3

2
// 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

BhalchandraSW
  • 714
  • 5
  • 13
0

Have a look at the Contacts Provider.

Nelson Wright
  • 506
  • 9
  • 18
0

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@email.com");
intent.putExtra(Intents.Insert.PHONE, "15417543010");

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

startActivity(intent);
Jéwôm'
  • 3,753
  • 5
  • 40
  • 73