在蜂窝/ ICS地址格式 [英] Address format in Honeycomb / ICS

查看:87
本文介绍了在蜂窝/ ICS地址格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它可以检索信息的设备上接触邮寄地址。我检索使用名片API使用类似于下面code街道地址,邮寄code,城市等信息。然后,我显示在不同的行地址和用户可以接受或按需要改变。

I have an app which can retrieve the mailing address from contact information on the device. I retrieve the information for street address, post code, city etc. using the contacts API using code similar to below. I then display the address on separate lines and the user can accept it or change it if desired.

String where = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; 
String[] params = new String[]{id, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE}; 
Cursor addrCur = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, where, params, null); 
...

while(addrCur.moveToNext()) {
    String street = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
    String city = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
    String state = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
    String postalCode = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
    String country = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
    ...
}       
addrCur.close();

这一直很好了Android 2.2 / 2.3,但我注意到3.x和更高的返回的整个地址可以被格式化为一个字符串在街上领域换行符。在设备上创建联系人/地址时,会发生此;如果我从同步Gmail的联系人,地址是正确检索(我怀疑是同步的信息被保存在正确的字段)。我看不出有什么办法让这些类型的地址的各个数据元素(街道,后code等)。这可能吗?是否有一个新的API,我需要使用?

This has worked fine with Android 2.2/2.3 but I noticed on 3.x and higher that the entire address that is returned can be formatted as a single string with line breaks in the STREET field. This occurs when the contact/address is created on the device; if I sync a contact from Gmail, the address is retrieved correctly (I suspect that the synced info is saved in the correct fields). I can't see any way to get the individual data elements (street, postcode, etc) for these types of addresses. Is this possible? Is there a new API I need to use?

推荐答案

我还没有找到一个方法来做到这一点。我发现的唯一的解决方法是通过充分利用光标 ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS 列获得完整的,格式化的地址,然后试图拆解打破它假设几个不同的标准打印格式。有没有办法输入在蜂窝/ ICS联系地址应用程式比使用自由格式的文本框等,所以我猜联系人应用程序不尝试并存储在数据库前自动解析它。

I haven't found a way to do it. The only workaround I've found is to get the full, formatted address by getting the ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS column from the cursor and then attempt to break it apart assuming a couple different standard formattings. There's no way to input an address in the Honeycomb/ICS Contacts app other than using a free-form text box, so I guess the Contacts app doesn't try and parse it automatically before storing it in the database.

希望我错了,有一个办法做到这一点 - 但我还没有找到它。

Hopefully I'm wrong and there is a way to do it - but I haven't found it yet.

这篇关于在蜂窝/ ICS地址格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆