Question

I am currently using Java ME to extract Addressbook (ContactList) fields in a device via PIM (JSR75 Spec). I am having problems on getting the value's maximum length of a field if the field's datatype is a String. I initially thought there's a method in the API that is like getFieldLength(int fieldId) but unfortunately found none.

Is there a way I can get this?

I need to know the field's data length because I only read the field definition itself. Not the values. I need to collect all the supported fields in a device. From the those fields, I need to get the field's name, data type and maximum length. We are putting the said infos to our server application for device porting purposes.

Was it helpful?

Solution

Retrieving the maximum length of a field is not part of the PIM API.

You can however work around that by attempting to write content of increasing length to the field.

Failure to write content will throw an Exception.

For each field you want to test, write 512 bytes, then 1kb, 2kb, 4kb...

My guess is that most phones will allow you to write all the data you want.

Remember to delete fields between write attempt.

If you really need to be precise to the byte, you can use dichotomy once you have found an upper limit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top