📜 ⬆️ ⬇️

Export and import personal phone data

Faced the problem that it was necessary to pick up your contact numbers and all the events in the calendar from the phone and transfer to another. Walking through different services did not find anything. I had to write everything myself.

I will not show all the program code, I will show you just how to pick up and write the numbers to the phone. The Nokie E60 works fine, I haven't tested it on other phones.

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

We take phones:
')
//
PIM pim = PIM.getInstance();
ContactList lists = null;
try {
// lists
lists = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
} catch (Exception e) {}

//
Enumeration contacts = null;
try {
contacts = lists.items();
} catch (PIMException ex) {
ex.printStackTrace();
}
//
Contact next = (Contact) contacts.nextElement();
//
int count = next.countValues(Contact.TEL);
String all_telephone = "";
for (int i = 0; i < count; i++) {
//
String phone = next.getString(Contact.TEL, i);
all_telephone += phone+"\n";
}
list = new StringItem("List:", all_telephone);


We are recording a new phone:

// ,
Contact create_next = lists.createContact();
int attrs = Contact.ATTR_HOME;
//
create_next.addString(Contact.TEL, attrs, "9379992");
//
create_next.addString(Contact.ORG, PIMItem.ATTR_NONE, " ");
try {
//
create_next.commit();
} catch (PIMException ex) {
ex.printStackTrace();
}

Source: https://habr.com/ru/post/81726/


All Articles