1

I am using following code for populating contacts in Android:

Intent addContactIntent = new Intent(Intent.ACTION_INSERT);
addContactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "Store Name");
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE, "1-869-270-9099");
addContactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL, "postal address");*

But I also need to populate city, street and zip in postal address. How to populate these fields using the above code? Or any alternate way to do so.

Tamás
  • 47,239
  • 12
  • 105
  • 124
Mahesh
  • 243
  • 1
  • 5
  • 13

1 Answers1

0

Ok here is what i have done.

                     ArrayList<ContentValues> data = new ArrayList<ContentValues>();
                    //Email
                      ContentValues row1 = new ContentValues();
                      row1.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
                      row1.put(Email.ADDRESS, "ADDRESSme");
                      data.add(row1);

                    //Website
                      ContentValues row2 = new ContentValues();
                      row2.put(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE);
                      row2.put(Website.URL, "URLme");
                      data.add(row2);

                      //name
                      ContentValues row3 = new ContentValues();
                      row3.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
                      row3.put(StructuredName.DISPLAY_NAME, "NameMe");
                      data.add(row3);

                      //Address
                      ContentValues row4 = new ContentValues();
                      row4.put(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
                      row4.put(StructuredPostal.CITY, "CityMe");
                      row4.put(StructuredPostal.COUNTRY, "COUNTRYme");
                      row4.put(StructuredPostal.STREET, "STREETme");
                      row4.put(StructuredPostal.POSTCODE, "POSTCODEme");
                      data.add(row4);

                      //Phone 

                      ContentValues row5 = new ContentValues();
                      row5.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
                      row5.put(Phone.NUMBER, "NUMBERme");
                      data.add(row5);

                      Intent i = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                      i.putParcelableArrayListExtra(Insert.DATA, data);

But one thing i need to remind you is that Insert.DATA is available only from API level 11.So this solution only works for Android 3.0+.

If you guys have any better solution please let me know.

monish george
  • 811
  • 7
  • 14