How do i get contacts stored in SIM card?

53 views
Skip to first unread message

wisdom...@gmail.com

unread,
Jul 17, 2014, 7:04:04 AM7/17/14
to codenameone...@googlegroups.com
Please i need help in getting the contacts stored in my sim card, if it can be done. I have tried the code below but it only gets contacts stored in the Phone's Internal memory. I've test the j2me build in my Nokia 5370c, but am not pleased with the result.

            String[] contactsId = ContactsManager.getAllContacts();
            
            for(String cid:contactsId){
                
                Contact c = ContactsManager.getContactById(cid);
                Object[] phones = c.getPhoneNumbers().values().toArray();
                String phos = "";

                for(Object phoo:phones){
                    phos = phos+(String)phoo+",";
                } 
                phos = phos.substring(0, phos.length() - 1);
                String contact = c.getFamilyName()+" "+c.getFirstName()+"["+phos+"]";
                System.out.println(contact);
            }

Shai Almog

unread,
Jul 17, 2014, 11:19:40 AM7/17/14
to codenameone...@googlegroups.com, wisdom...@gmail.com
Are these contacts returned when you are using the J2ME PIM API?
We just invoke that API.

wisdom...@gmail.com

unread,
Jul 17, 2014, 1:04:38 PM7/17/14
to codenameone...@googlegroups.com, wisdom...@gmail.com
Shai, thanks for your reply. Am using the com.codename1.contacts.ContactManager class. I've not tried 
the PIM API directly, if that's what you mean.
I looked around and the PIM API guys said that PIM  returns two Lists, One contains phone contacts and the other SIM contacts.
Is ContactManager expected to return both List?

Shai Almog

unread,
Jul 18, 2014, 12:11:36 AM7/18/14
to codenameone...@googlegroups.com, wisdom...@gmail.com
Can you point me to the place where they say that?

wisdom...@gmail.com

unread,
Jul 18, 2014, 5:32:31 AM7/18/14
to codenameone...@googlegroups.com, wisdom...@gmail.com

Ok.

According to the PIM java Doc here.


public abstract PIMList openPIMList(int pimListType,

                                    int mode,
                                    java.lang.String name)
                             throws PIMException
Open a named PIM List. Only string names returned by listPIMLists(int) can be used to open a list.
Parameters:
pimListType - int representing the PIM list type to open, either CONTACT_LISTEVENT_LIST, or TODO_LIST.
mode - in which the List is opened, either READ_ONLYREAD_WRITE, or WRITE_ONLY.
name - the named List to open
Returns:
the named List.

Throws:
PIMException - If the list is not available, the operation is unsupported or an error occurs.
java.lang.SecurityException - if the application is not given permission that matches the requested mode.
java.lang.IllegalArgumentException - If an invalid mode is provided as a parameter or if pimListType is not a valid PIM list type.
java.lang.NullPointerException - If name is null.


I also saw sample codes that's basically saying: 

 PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, contactsFrom[i]);
               
 /*Where
     String[] contactsFrom = pim.listPIMLists(PIM.CONTACT_LIST);
  and
      i = index of the desired memory {SIM,Phone,Contacts}
*/


Sample Codes:


Shai Almog

unread,
Jul 18, 2014, 11:20:28 AM7/18/14
to codenameone...@googlegroups.com, wisdom...@gmail.com
I don't see any mention of SIM card contacts vs. device contacts.

wisdom...@gmail.com

unread,
Jul 18, 2014, 1:14:55 PM7/18/14
to codenameone...@googlegroups.com, wisdom...@gmail.com
Thanks for your time sir.
Reply all
Reply to author
Forward
0 new messages