开始添加新联系人的活动,并通过结构化数据 [英] Start add new contact activity and pass structured data
问题描述
可以开始默认的人/联系人活动,并通过像结构化数据
分离姓氏和名字,电话型城市,邮递code和类似的数据。
我用下面类似code:
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 );
这工作正常,但我不能指定哪些是例如邮政code,什么是城市或地方。
我发现样品这样这里,但我不能开始添加新的联系人意图之前,所以用户不能保存他接触之前,做一些修改。 code立即将无需用户交互的联系人。
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.
任何帮助将是AP preciable。
Any help would be appreciable.
推荐答案
至于你的信息,你可以使用ContactsContract.Intents.Insert.DATA,其目的是要插入多个数据items.Like城市,国家等的地址栏。但真正的问题是,它无法使用的前11 API
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.
下面是如何开展工作。
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);
这篇关于开始添加新联系人的活动,并通过结构化数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!