How can i show a pre populated postal address in contacts screen with street , city , zip on android

混江龙づ霸主 提交于 2019-12-11 05:35:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8488777/how-can-i-show-a-pre-populated-postal-address-in-contacts-screen-with-street-c

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