Start add new contact activity and pass structured data

荒凉一梦 提交于 2019-12-11 11:40:41

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/15565837/start-add-new-contact-activity-and-pass-structured-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!