1

What is the correct way to check if a PIM string array is supported?

can I use:

if (MyContactList.isSupportedField(Contact.ADDR)){...}

or would I be better to check :

if (MyContactList.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_STREET))

or both?

The following is my problem code:

if (MyContactList.isSupportedField(Contact.ADDR)) {
//...
//...
String[] AaddressLines = CurrentContact.getStringArray(Contact.ADDR, 0);;
}

It doesn't matter if I comment out the "if" block it always crashes. Only fix I can see is to ignore addresses altogether, please help.

gnat
  • 6,213
  • 108
  • 53
  • 73
Pedro
  • 11
  • 1

2 Answers2

3

Better way to do like this. Its working fine for me. See this sample,

String[] lists = pim.listPIMLists(PIM.CONTACT_LIST);
ContactList clist =  (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, lists[index]);
Enumeration contacts = clist.items();
while (contacts.hasMoreElements()) {

Contact c = (Contact) contacts.nextElement(); 
int[] fields = clist.getSupportedFields();
for (int count = 0; count < fields.length; count++) {
int value = fields[count];
// do smething

if (value == Contact.ADDR && c.countValues(Contact.ADDR) > 0) {
String[] addr = c.getStringArray(Contact.ADDR, 0);
...
...
  }
 }
}
bharath
  • 14,283
  • 16
  • 57
  • 95
0

On device I could not get Contact.NAME even though isSupportedField(Contact.NAME) returned true. Then I had to get the individual fields of Contact.NAME by calling

String[] Names = ContactObj.getStringArray(Contact.NAME, 0);

When you concat all elements in Names array, you get Contact name. This worked on all devices.

Kulai
  • 630
  • 1
  • 6
  • 12