public int ParseContactMethods(ContextWrapper contextWrapper, Uri
uriContactMethods)
{
int nRet = PhoneDef.ErrorMessage.DERR_SUCCEED;
try {
String selection = "\"person\" = "+ContactID;
Cursor Cursor =
contextWrapper.getContentResolver().query(uriContactMethods,null,selection,null,null);
if (Cursor.moveToFirst()) {
int nRow = Cursor.getCount();//get rows of phones database
Log.d("ContactMethodsCount", String.valueOf(nRow));
do {
int nColumnKind = Cursor.getColumnIndex("kind");
String strKind = Cursor.getString(nColumnKind);
if (strKind != null)
Log.d("Kind", strKind);
int nColumnType = Cursor.getColumnIndex("type");
String strType = Cursor.getString(nColumnType);
if (strType != null)
Log.d("Type", strType);
int nColumnData = Cursor.getColumnIndex("data");
String strData = Cursor.getString(nColumnData);
if (strData != null)
Log.d("data", strData);
int nColumnAuxData = Cursor.getColumnIndex("aux_data");
String strAuxData = Cursor.getString(nColumnAuxData);
if (strAuxData != null)
Log.d("aux_data", strAuxData);
if( strKind != null && strType != null && strData !=
null )
{
FieldsContact contactField = new FieldsContact();
if( strKind.equals(String.valueOf(1)))//1 means
Email
{
if( strType.equals(String.valueOf(0))
)//0Contacts.ContactMethodsColumns.TYPE_CUSTOM
{}//暂时不支持
else if( strType.equals(String.valueOf(1))
)//1Contacts.ContactMethodsColumns.TYPE_HOME
contactField.setTid(PhoneDef.ContactTID.TID_EMAIL1);
else if( strType.equals(String.valueOf(2))
)//2Contacts.PhonesColumns.TYPE_WORK
contactField.setTid(PhoneDef.ContactTID.TID_EMAIL2);
else if( strType.equals(String.valueOf(3))
)//3Contacts.PhonesColumns.TYPE_OTHER
contactField.setTid(PhoneDef.ContactTID.TID_EMAIL3);
else
contactField.setTid(PhoneDef.ContactTID.TID_EMAIL1);//default
contactField.setCharSet(1);
contactField.setValue(strData.getBytes("UTF-8"));
arrayField.add(contactField);
}
else if( strKind.equals(String.valueOf(2)))//2 means
postal address
{
if( strType.equals(String.valueOf(0))
)//0Contacts.ContactMethodsColumns.TYPE_CUSTOM
{}//暂时不支持
else if( strType.equals(String.valueOf(1))
)//1Contacts.ContactMethodsColumns.TYPE_HOME
contactField.setTid(PhoneDef.ContactTID.TID_HOMEADDRESS);
else if( strType.equals(String.valueOf(2))
)//2Contacts.PhonesColumns.TYPE_WORK
contactField.setTid(PhoneDef.ContactTID.TID_BUSINESSADDRESS);
else if( strType.equals(String.valueOf(3))
)//3Contacts.PhonesColumns.TYPE_OTHER
contactField.setTid(PhoneDef.ContactTID.TID_OTHERADDRESS);
else
contactField.setTid(PhoneDef.ContactTID.TID_HOMEADDRESS);//default
contactField.setCharSet(1);
contactField.setValue(strData.getBytes("UTF-8"));
arrayField.add(contactField);
}
else if( strKind.equals(String.valueOf(3)) )//3
means IM
{
if( strAuxData.equals("pre:0") )//AIM
contactField.setTid(PhoneDef.ContactTID.TID_AIM);
else if( strAuxData.equals("pre:1") )//windows
live
contactField.setTid(PhoneDef.ContactTID.TID_WINDOWSLIVE);
else if( strAuxData.equals("pre:2") )//yahoo
contactField.setTid(PhoneDef.ContactTID.TID_YAHOO);
else if( strAuxData.equals("pre:3") )//skype
contactField.setTid(PhoneDef.ContactTID.TID_SKYPE);
else if( strAuxData.equals("pre:4") )//QQ
contactField.setTid(PhoneDef.ContactTID.TID_QQ);
else if( strAuxData.equals("pre:5") )//google
talk
contactField.setTid(PhoneDef.ContactTID.TID_GOOGLETALK);
else if( strAuxData.equals("pre:6") )//ICQ
contactField.setTid(PhoneDef.ContactTID.TID_ICQ);
else if( strAuxData.equals("pre:7") )//Jabber
contactField.setTid(PhoneDef.ContactTID.TID_JABBER);
else
contactField.setTid(PhoneDef.ContactTID.TID_AIM);//default
contactField.setCharSet(1);
contactField.setValue(strData.getBytes("UTF-8"));
arrayField.add(contactField);
}
else
{
Log.i("Error", "ContactMethods's Kind is
wrong");
}
}
} while (Cursor.moveToNext());
}
nRet = PhoneDef.ErrorMessage.DERR_SUCCEED;
Cursor.close();
} catch (Exception e) {
Log.i("ParseContactMethods Exception", e.toString());
e.printStackTrace();
nRet = PhoneDef.ErrorMessage.DERR_UNKNOWN;
}
return nRet;
}
2008/12/29 roland <[email protected]>
>
> The value of the Contacts.ContactMethods.KIND are int type, not string
> type. Try String selection = Contacts.ContactMethods.KIND
> +" = 1";
>
> On 21 déc, 03:50, jphdsn <[email protected]> wrote:
> > hi, I code an app and want to retrieve email from Contacts app of
> > android. If somebody knows how to retrieve the mails of a contact...
> > it will be cool or if someone could tell me why the code below doesn't
> > work and how it could be work...
> >
> > String selection = Contacts.ContactMethods.KIND
> > +"="+Contacts.ContactMethods.CONTENT_EMAIL_TYPE;
> >
> > Cursor groupCursor1 = managedQuery(
> > Contacts.ContactMethods.CONTENT_URI, null,selection,null, null);
> >
> > thanks a lot
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---