Reputation: 664
I have to develop solution based on getting data from address book. Those data must be saved into text format. I coded it with Java™ Platform Micro Edition SDK 3.0.
public void getAddrBook() throws Exception{
addrStr= new StringBuffer("");
pim = PIM.getInstance();
try{
contactList = (ContactList)pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
itemList.removeAllElements();
int kk=0;
for (Enumeration items = contactList.items(); items.hasMoreElements();kk++) {
PIMItem item = (PIMItem)items.nextElement();
itemList.addElement(item);
if (kk>5) break;
//detailed enumeration of fields
int[] fields = item.getPIMList().getSupportedFields();
for (int i = 0; i < fields.length; i++) {
int field = fields[i];
int dataType = item.getPIMList().getFieldDataType(field);
String label = item.getPIMList().getFieldLabel(field);
//checking type of PIMItem
//can be STRING, BOOLEAN, STRING_ARRAY, DATE, INT, BINARY
if (dataType==PIMItem.STRING){
for (int j=0; j
}
//String sValue = item.getString(field, 0);
//System.out.println("["+label+"] - "+sValue);
//System.out.println("["+label+"] - ");//+sValue);
}
}
}
}
catch(PIMException e){
throw new Exception("Some errors with access to address book");
//TODO: check empty list and other
}
}
But this code works only in emulator and doesn't work in real phone. How should I use PIM for saving data in text format?
Also, I allowed access to contact book. I think error is using PIM structure. I need some working sample. Who has it? (:
Upvotes: 1
Views: 1246
Reputation: 503
The JSR75 PIM API has security features built-in that require applications to be digitally signed by a trusted source. Signing can be done at sites like GeoTrust (I have used it for AT&T on a Sony Ericsson W810).
In addition to signing the application, you will need to enable permissions in the application's JAD file. The following 6 permissions are possible for the PIM API.
javax.microedition.pim.ContactList.read
javax.microedition.pim.ContactList.write
javax.microedition.pim.EventList.read
javax.microedition.pim.EventList.write
javax.microedition.pim.ToDoList.read
javax.microedition.pim.ToDoList.write
Upvotes: 2