1

Is possible to start default people/contact activity and pass structured data like separated first name and last name, phone type, city, postal code and similar data. I use following similar code:

Intent addContactIntent = new Intent(Intent.ACTION_INSERT); 
addContactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);              
addContactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL, "abc 2343");      
startActivity(addContactIntent );   

This works fine but I can't specify which is for example postal code, and what is city or place. I found samples like this here but I cant start add new contact intent before, so user can't edit something before he saves contact. Code immediately saves the contact without user interaction.

Any help would be appreciable.

Community
  • 1
  • 1
Nikola Jovic
  • 2,329
  • 2
  • 16
  • 17

1 Answers1

0

As for your information you can use ContactsContract.Intents.Insert.DATA ,which is designed to insert multiple data items.Like city,state etc for the address field.But the real problem is it in not available prior to API 11.

Here is how its work.

  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);
   //Address
   ContentValues row4 = new ContentValues();
   row4.put(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
   row4.put(StructuredPostal.CITY, "CityMe");//Pre populating  city
   row4.put(StructuredPostal.COUNTRY, "COUNTRYme");//Pre populating  country
   row4.put(StructuredPostal.STREET, "STREETme");////Pre populating  street
   row4.put(StructuredPostal.POSTCODE, "POSTCODEme");//
   data.add(row4);

  Intent i = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
  i.putParcelableArrayListExtra(Insert.DATA, data);
monish george
  • 811
  • 7
  • 14
  • Where would you start looking if the structured address does not appear in the contact editor of the intent? I'm passing both Website and StructuredPostal as two distinct rows of the same ArrayList, but only the website is shown in the editor. I've made sure none of the address components are null. – Jere Käpyaho Feb 20 '14 at 15:28