发布于 2024-12-20 18:14:13 字数 8 浏览 1 评论 0原文

continue

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2024-12-27 18:14:13

好的,这就是我所做的。

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

但我需要提醒您的一件事是 Insert.DATA 仅适用于 API 级别 11。因此该解决方案仅适用于 Android 3.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文