Cannot access SIM phonebook in Nokia

I am trying to access the phone book of a phone and SIM phones on the Nokia 5130c-2 XpressMusic. The application works without errors, but it only returns numbers from the phone book. When I list the available phone books using this code

String[] all_contact_lists=PIM.getInstance().listPIMLists(PIM.CONTACT_LIST); 

he gives me both phonebook and SIM card lists. those. 1. Phone 2. SIM

I tried to explicitly read from the SIM card using this code, but it still doesn't return anything (although I have numbers stored on the SIM card). Code:

 ContactList clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, "SIM"); 

Here is my full code ::

 import javax.microedition.midlet.*; import javax.microedition.pim.*; import com.sun.lwuit.*; import java.util.*; public class contacts extends MIDlet { private List my_list=new List(); private String[] names=null; public void startApp() { Display.init(this); Form my_form=new Form("Contacts List"); String[] all_contact_lists=PIM.getInstance().listPIMLists(PIM.CONTACT_LIST); //Iterate through available phonebooks for(int db=0; db<all_contact_lists.length; db++) { try { ContactList clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, all_contact_lists[db]); Enumeration contacts=clist.items(); while(contacts.hasMoreElements()) { Contact contact=(Contact)contacts.nextElement(); try{ String phone_contact=""; names=contact.getStringArray(Contact.NAME, 0); for(int i=0; i<names.length; i++) { if(names[i]!=null) phone_contact+=" "+names[i]; } //my_list.addItem(phone_contact); int phone_numbers=contact.countValues(Contact.TEL); if(phone_numbers>0) { String number=contact.getString(Contact.TEL,0); my_list.addItem(phone_contact+":"+number); } else { my_list.addItem(phone_contact); } //clist.removeContact(contact); } catch (Throwable t) { t.printStackTrace(); } } } catch (PIMException ex) { ex.printStackTrace(); } } //my_list.addItem(all_contact_lists); my_list.setRenderingPrototype("WWWWWWWWWWWWWWWWWWWW"); my_form.addComponent(my_list); my_form.show(); } public void pauseApp(){} public void destroyApp(boolean unconditional){} } 
+4
source share
2 answers

If you use a phone number for text or call, you can do this with only one line of code. Now it’s obvious that problems with the phone’s software can affect how the application accesses the PIM API. In addition, if the memory used in the settings for contacting the phone is installed on the SIM (alone), you cannot access the contacts in the phone’s memory and vice versa, make sure that both of them are used. Try it if you still have a problem,

 //make a text field in LWUIT that is declared globally PhnNmbr = new TextField(); //set it to only accept phonenumber PhnNmbr.setConstraint(TextField.PHONENUMBER); //tell the user how to access phonebook PhnNmbr.setHint("Press T9 then 'Search' to search phonebook"); //add a button or command //that either sends an sms to //or calls the number in the text field //or anything else you want to do with it 

When the user presses T9, the TextField is considered the LCDUI text field with the PHONENUMBER parameter, which allows him to search for contacts in the Sim and phone’s memory, so you will notice a search command (usually in the lower center). Also make sure that the memory used for the phone is installed on Phone and Sim.

+2
source

Excerpt from PIM javadoc

PIMItems refer to their data through fields. A field is a group of data values ​​that have similar characteristics. An example TEL field that indicates data values ​​for this particular field are phone numbers. Classes that implement the PIMItem interface defines the possible fields that are for this particular class (for example, TEL defined in the contact interface as a field in which the contact can support).

A PIM implementation is not required to support all possible fields defined in classes that implement the PIMItem interface. . because no native PIM databases contain all the fields defined in this API. The PIMList that owns PIMItem determines that the fields PIMItem can support and store (all PIMItems in a specific PIMList support the same set of fields). PIMList.getSupportedFields() from a specific PIMItem PIMList is used to determine which fields are supported in this clause. Since not all possible fields are actually supported in a specific PIMItem, all fields must be checked for support in the PIMList element using PIMList.isSupportedField(int) before use in any search or storage method.

Each field has the following information available to it:

  • Zero or more data values ​​associated with a field
  • Data Value Attributes for a Field
  • Descriptive label for the field
  • Type of data associated with the field

Fill in PIM javadoc can be read on this.

Check if the device supports the Contact.NAME and Contact.TEL PIM fields on your device. If not, you need to call PIMList.getSupportedFields() to get the supported field on the device and, accordingly, get the name and phone number for this device. If I remember correctly, an alternate field for the name Contact.FORMATTED_NAME .

+1
source

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


All Articles