Export and import personal data phone

Faced with the problem that it was necessary to collect their contact numbers and all calendar events from the phone and transferred to another. Walking around to the different services found nothing. Had to write everything myself.

I will not show all the code of the program, will show only how to take and record the numbers in the phone. On Nokie E60 is working fine on other phones I test.

j2me allows you to import and export personal data is giving their API for this purpose. Personal data includes: contacts, memos and tasks. More theory and description of all methods of the class can be found here or here.

Pick up the phone:

//run the instance of the class of personal data
PIM pim = PIM.getInstance();
Lists ContactList = null;
try {
//all our contacts pick up the variable lists
lists = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
} catch (Exception e) {}

// Iterate through phones and save them
Enumeration contacts = null;
try {
contacts = lists.items();
} catch (PIMException ex) {
ex.printStackTrace();
}
//variable to store the contacts separately
Next Contact = (Contact) contacts.nextElement();
//the number of phones
int count = next.countValues(Contact.TEL);
All_telephone String = "";
for (int i = 0; i < count; i++) {
//save the data and accumulate them
String phone = next.getString(Contact.TEL, i);
all_telephone += phone+"\n";
}
list = new StringItem("List:", all_telephone);


write new phone number:

//a variable to premise data, which we will write
Contact create_next = lists.createContact();
int attrs = Contact.ATTR_HOME;
//attribute of the phone
create_next.addString(Contact.TEL, attrs, "9379992");
//attribute name
create_next.addString(Contact.ORG, PIMItem.ATTR_NONE, "Wait for me");
try {
//stored in the phone
create_next.commit();
} catch (PIMException ex) {
ex.printStackTrace();
}
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Integration of PostgreSQL with MS SQL Server for those who want faster and deeper

Custom database queries in MODx Revolution

Parse URL in Zend Framework 2