我正在使用 android 1.5 api,我知道它已被弃用,但它的客户端要求。我正在使用以下代码读取联系人地址,但每次它给地址计数为零。我无法找出问题所在
private void getAddress(String _Id)
{
Cursor curAddress=null;
try
{
String addrWhere = Contacts.ContactMethods.PERSON_ID + " = ? AND " + Contacts.ContactMethods.KIND + " = ?";
String[] addrWhereParams = new String[]{_Id, Contacts.ContactMethods.CONTENT_POSTAL_ITEM_TYPE};
curAddress = _resolver.query(Contacts.ContactMethods.CONTENT_URI, null, addrWhere, addrWhereParams, null);
int i=0;
int aCount = curAddress.getCount();
String[] aType = new String[aCount];
String[] aAddrss = new String[aCount];
while(curAddress.moveToNext())
{
aType[i] = curAddress.getString(curAddress.getColumnIndex(Contacts.ContactMethodsColumns.TYPE));
aAddrss[i] = curAddress.getString(curAddress.getColumnIndex(Contacts.ContactMethodsColumns.DATA));
i++;
}
}
catch (Exception e)
{
Log.e(StaticVariables.TAG, "getAddress: " + e.getMessage());
}
finally
{
if(curAddress!=null) curAddress.close();
}
}