Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Question Retrieve SIM contacts

    Hi all,

    Is it possible to retrieve the sim contacts?
    Here its possible to retrieve the contacts from phone contacts only.
    How to retrieve the sim contacts and add the new contact to sim?



    Regards,
    Bharath.C

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Retrieve SIM contacts

    Quote Originally Posted by bhakki View Post
    Hi all,

    Is it possible to retrieve the sim contacts?
    Here its possible to retrieve the contacts from phone contacts only.
    How to retrieve the sim contacts and add the new contact to sim?

    Regards,
    Bharath.C
    Yes, all this is possible on using JSR -75 PIM api's on Nokia S40 devices.

    refer to FN wiki -
    http://wiki.forum.nokia.com/index.ph...ook_in_Java_ME
    http://wiki.forum.nokia.com/index.ph...act_in_Java_ME
    http://wiki.forum.nokia.com/index.ph...cts_in_Java_ME

    or refer to PDAPDemo PIM example of WKT

    using String[] lists = pim.listPIMLists(PIM.CONTACT_LIST);

    Code:
    PIM pim = PIM.getInstance();
    String[] lists = pim.listPIMLists(PIM.CONTACT_LIST); // you get the list 0 and 1, where 0 is sim list and 1 is phone book list
    for (int i = 0; i < lists.length; i++) // get both phone book memorry and SIM card
    				{
    					PIMList list = null;
    					try
    					{
    						list = pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, lists[i]);
    					}
    					catch (PIMException e)
    					{
    					}
    // do what you want with the PIM list of both  add,edit,delete and then close the list.
    }
    Thanks,
    Ekta

  3. #3
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Retrieve SIM contacts

    Is this working for you?
    I cant retrieve the SIM contacts.
    I can retrieve Only phonecontacts.
    How to retrieve the SIM contacts?


    Regards,
    Bharath...

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Retrieve SIM contacts

    Quote Originally Posted by bhakki View Post
    Is this working for you?
    I cant retrieve the SIM contacts.
    I can retrieve Only phonecontacts.
    How to retrieve the SIM contacts?


    Regards,
    Bharath...
    On which device you are testing it ?

    just try this:
    PIM pim = PIM.getInstance();
    String[] lists = pim.listPIMLists(PIM.CONTACT_LIST); // you get the list 0 and 1, where 0 is sim list and 1 is phone book list
    And print the no. of lists you get in this Response.....

    Using this you can access SIM contact book on S40, I have tested this on Nokia 6500 slider.
    Thanks,
    Ekta

  5. #5
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Retrieve SIM contacts

    I tested on 2700 classic.
    Its reading the SIM numbers.
    But i cant retrieve the values from SIM, It retrieve the phone contacts value only.


    Regards,
    Bharath.c

  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Retrieve SIM contacts

    Quote Originally Posted by bhakki View Post
    I tested on 2700 classic.
    Its reading the SIM numbers.
    But i cant retrieve the values from SIM, It retrieve the phone contacts value only.


    Regards,
    Bharath.c
    You say "Its reading the SIM numbers" but you cant retrieve the values from SIM.... what do you mean by this... if you are able read the contact Objects from SIM card... you are not able to get the phone numbers or name. Are you trying Contact.FormatedName or only Contact.Name or Contact.Tel?
    Thanks,
    Ekta

  7. #7
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Retrieve SIM contacts

    Normally im using Contact.NAME_GIVEN and Contact.NAME_FAMILY for getting the names.
    But i didnt using Contact.FormatedName.

    And I cant get some telephone numbers from phone contact.
    I used the all priorities like Contact.ATTR_HOME...
    But I cant get some telephone numbers only.


    Regards,
    Bharath...

  8. #8
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Retrieve SIM contacts

    Quote Originally Posted by bhakki View Post
    Normally im using Contact.NAME_GIVEN and Contact.NAME_FAMILY for getting the names.
    But i didnt using Contact.FormatedName.

    And I cant get some telephone numbers from phone contact.
    I used the all priorities like Contact.ATTR_HOME...
    But I cant get some telephone numbers only.


    Regards,
    Bharath...
    Reading both the list - SIM & Phone try fetch - Contact.TEL
    and search within like:
    Code:
    // Numbers
    	int n = contact.countValues(Contact.TEL); 
    	if(n>0)
    	{
    		for (int k = 0; k < n; k++)
    		{
    		int attrs = contact.getAttributes(Contact.TEL, k);
    		try
    		{
    			String tel = contact.getString(Contact.TEL, k);
    			System.out.println("Tel :" +tel);
    		}
    		catch (IndexOutOfBoundsException ex)
    		{
    		}
    	        }
    	}
    Cut & Paste your Contact reading code here.
    Thanks,
    Ekta

  9. #9
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Retrieve SIM contacts

    I got the this exception while reading the sim contact,
    java.lang.IndexOutBoundException: Empty field

    How to resolve this exception???


    Regards,
    Bharath...

  10. #10
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Retrieve SIM contacts

    Quote Originally Posted by bhakki View Post
    I got the this exception while reading the sim contact,
    java.lang.IndexOutBoundException: Empty field

    How to resolve this exception???


    Regards,
    Bharath...
    Before trying to access any element check for its support using -
    if (list.isSupportedField(Contact.TEL));

    try this
    Code:
    // Name
    		String name = null;
                     try {
    		if (list.isSupportedField(Contact.FORMATTED_NAME) && contact.countValues(Contact.FORMATTED_NAME) > 0)
            							{
                                          name = contact.getString(Contact.FORMATTED_NAME, 0);
                                        }
    								}catch(Exception e){}
                                    if(name==null)
                                    {
                                    try {
                                    if(list.isSupportedField(Contact.NAME) && contact.countValues(Contact.NAME) > 0)	                                    
                                        {
                                        name="";
                                        String[] newname = contact.getStringArray(Contact.NAME, 0);
                                        if(newname[0]!=null) name=newname[0];
                                        if(newname[1]!=null && newname[0]!=null ) name=name+" "+newname[1];                                    
                                        if(newname[1]!=null && newname[0]==null ) name=newname[1];                                    
                                        if(newname[0]==null && newname[1]==null) name="-";
                                        }
                                    }catch(Exception e){}
    								}
    Thanks,
    Ekta

  11. #11
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Retrieve SIM contacts

    Ya. i checked like this only. but i got the same exception.

    Here i post my code.

    for (int index = 0; index < lists.length; index++)
    {
    PIMList clist = null;
    Enumeration contacts = null;
    try {
    clist = pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, lists[index]);
    contacts = clist.items();
    } catch (Exception e) {
    e.printStackTrace();
    }


    while (contacts.hasMoreElements()) {

    Contact c = (Contact) contacts.nextElement();
    String fName = "";
    String lName = "";
    String nickName = "";
    String email = "";
    String dob = "";
    String notes = "";
    String url = "";
    String job = "";
    String org = "";
    if (clist.isSupportedField(Contact.NAME)) {
    String[] nameValues = c.getStringArray(Contact.NAME, 0);
    if (nameValues != null) {
    if (nameValues[0] != null && !nameValues[0].equalsIgnoreCase("")) {
    fName = nameValues[0];
    }
    if (nameValues[1] != null && !nameValues[1].equalsIgnoreCase("")) {
    lName = nameValues[1];
    }
    }
    }
    if (clist.isSupportedField(Contact.NICKNAME)) {
    if (c.getString(Contact.NICKNAME, 0) != null) {
    nickName = c.getString(Contact.NICKNAME, 0);
    }
    }
    if (clist.isSupportedField(Contact.EMAIL)) {
    if (c.getString(Contact.EMAIL, 0) != null) {
    email = c.getString(Contact.EMAIL, 0);
    }
    }
    if (clist.isSupportedField(Contact.BIRTHDAY)) {
    String date = dateToString(c.getDate(Contact.BIRTHDAY, 0));
    if (date != null) {
    dob = date;
    }
    }
    if (clist.isSupportedField(Contact.NOTE)) {
    if (c.getString(Contact.NOTE, 0) != null) {
    notes = c.getString(Contact.NOTE, 0);
    }
    }
    if (clist.isSupportedField(Contact.TITLE)) {
    if (c.getString(Contact.TITLE, 0) != null) {
    job = c.getString(Contact.TITLE, 0);
    }
    }
    if (clist.isSupportedField(Contact.URL)) {
    if (c.getString(Contact.URL, 0) != null) {
    url = c.getString(Contact.URL, 0);
    }
    }
    if (clist.isSupportedField(Contact.ORG)) {
    if (c.getString(Contact.ORG, 0) != null) {
    org = c.getString(Contact.ORG, 0);
    }
    }
    }



    What mistake i will do in my code????


    Bharath....

  12. #12
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Retrieve SIM contacts

    Quote Originally Posted by bhakki View Post
    Ya. i checked like this only. but i got the same exception.

    Here i post my code.

    for (int index = 0; index < lists.length; index++)
    {
    PIMList clist = null;
    Enumeration contacts = null;
    try {
    clist = pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, lists[index]);
    contacts = clist.items();
    } catch (Exception e) {
    e.printStackTrace();
    }


    while (contacts.hasMoreElements()) {

    Contact c = (Contact) contacts.nextElement();
    String fName = "";
    String lName = "";
    String nickName = "";
    String email = "";
    String dob = "";
    String notes = "";
    String url = "";
    String job = "";
    String org = "";
    if (clist.isSupportedField(Contact.NAME)) {
    String[] nameValues = c.getStringArray(Contact.NAME, 0);
    if (nameValues != null) {
    if (nameValues[0] != null && !nameValues[0].equalsIgnoreCase("")) {
    fName = nameValues[0];
    }
    if (nameValues[1] != null && !nameValues[1].equalsIgnoreCase("")) {
    lName = nameValues[1];
    }
    }
    }
    if (clist.isSupportedField(Contact.NICKNAME)) {
    if (c.getString(Contact.NICKNAME, 0) != null) {
    nickName = c.getString(Contact.NICKNAME, 0);
    }
    }
    if (clist.isSupportedField(Contact.EMAIL)) {
    if (c.getString(Contact.EMAIL, 0) != null) {
    email = c.getString(Contact.EMAIL, 0);
    }
    }
    if (clist.isSupportedField(Contact.BIRTHDAY)) {
    String date = dateToString(c.getDate(Contact.BIRTHDAY, 0));
    if (date != null) {
    dob = date;
    }
    }
    if (clist.isSupportedField(Contact.NOTE)) {
    if (c.getString(Contact.NOTE, 0) != null) {
    notes = c.getString(Contact.NOTE, 0);
    }
    }
    if (clist.isSupportedField(Contact.TITLE)) {
    if (c.getString(Contact.TITLE, 0) != null) {
    job = c.getString(Contact.TITLE, 0);
    }
    }
    if (clist.isSupportedField(Contact.URL)) {
    if (c.getString(Contact.URL, 0) != null) {
    url = c.getString(Contact.URL, 0);
    }
    }
    if (clist.isSupportedField(Contact.ORG)) {
    if (c.getString(Contact.ORG, 0) != null) {
    org = c.getString(Contact.ORG, 0);
    }
    }
    }



    What mistake i will do in my code????


    Bharath....
    Problem lines hi lighted:
    replace by

    Code:
    // Name
    		String name = null;
                     try {
    			if (list.isSupportedField(Contact.FORMATTED_NAME) && contact.countValues(Contact.FORMATTED_NAME) > 0)
    				{
                                          name = contact.getString(Contact.FORMATTED_NAME, 0);
                                        }
    				}catch(Exception e){}
                                    if(name==null)
                                    {
                                    try {
                                    if(list.isSupportedField(Contact.NAME) && contact.countValues(Contact.NAME) > 0)	                                    
                                        {
                                        name="";
                                        String[] newname = contact.getStringArray(Contact.NAME, 0);
                                        if(newname[0]!=null) name=newname[0];
                                        if(newname[1]!=null && newname[0]!=null ) name=name+" "+newname[1];                                    
                                        if(newname[1]!=null && newname[0]==null ) name=newname[1];                                    
                                        if(newname[0]==null && newname[1]==null) name="-";
                                        }
                                    }catch(Exception e){}
    								}
    Put some alerts for testing after each field and you will get where it stuck's.
    Thanks,
    Ekta

  13. #13
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Retrieve SIM contacts

    Thanks Ekta....

    Most of the problem was solved but i have 1 more problem.
    I cant retrieve the some telephone number from phone contacts.
    I was created the contact as general format.
    I used all attributes for retrieve the telephone numbers.
    Like,

    int phoneNumbers = c.countValues(Contact.TEL);

    if (value == Contact.TEL && phoneNumbers > 0) {


    for (int i = 0; i < phoneNumbers; i++) {
    if (c.getAttributes(Contact.TEL, i) == Contact.ATTR_HOME) {
    String homeNo = c.getString(Contact.TEL, i);

    } else if (c.getAttributes(Contact.TEL, i) == Contact.ATTR_FAX) {

    String faxNo = c.getString(Contact.TEL, i);

    } else if (c.getAttributes(Contact.TEL, i) == Contact.ATTR_WORK) {

    String workNo = c.getString(Contact.TEL, i);

    } else if (c.getAttributes(Contact.TEL, i) == Contact.ATTR_MOBILE) {

    String mobileNo = c.getString(Contact.TEL, i);

    } else if (c.getAttributes(Contact.TEL, i) == Contact.ATTR_NONE || c.getAttributes(Contact.TEL, i) == Contact.ATTR_OTHER || c.getAttributes(Contact.TEL, i) == Contact.ATTR_AUTO || c.getAttributes(Contact.TEL, i) == Contact.ATTR_PREFERRED || c.getAttributes(Contact.TEL, i) == Contact.ATTR_ASST || c.getAttributes(Contact.TEL, i) == Contact.ATTR_PAGER || c.getAttributes(Contact.TEL, i) == Contact.ATTR_SMS) {

    String otherNo = c.getString(Contact.TEL, i);

    }


    Is this correct?
    Some telephone numbers not comes into the any conditions.

    Regards,
    Bharath...
    Last edited by bhakki; 2010-06-22 at 12:20.

  14. #14
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Retrieve SIM contacts

    Some telephone don't come because they might not be defined in this way -
    try
    Code:
    // Numbers
            private static String[] attrDescList = 
    	{
    		ATTR_ASST, ATTR_AUTO, ATTR_FAX, ATTR_HOME, ATTR_MOBILE, ATTR_OTHER, ATTR_PAGER, ATTR_PREFERRED, ATTR_SMS, ATTR_WORK
    	};
    	int n = contact.countValues(Contact.TEL); 
    	if(n>0)
    	{
    		for (int k = 0; k < n; k++)
    		{
    		int attrs = contact.getAttributes(Contact.TEL, k);
    		try
    		{
    			String tel = contact.getString(Contact.TEL, k);
    			System.out.println("attrs: "+attrDescList [attrs]+ "       " +Tel :" +tel);
    		}
    		catch (IndexOutOfBoundsException ex)
    		{
    		}
    	        }
    	}
    Thanks,
    Ekta

  15. #15
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Retrieve SIM contacts

    Hi,

    I think this is problem with s40 series mobiles.
    Because this problem only occured when i retrieving the contact as general format.
    I dont know How to resolve this issue????

    I got the contact.countValues(Contact.TEL) is 0 when i retrieving the general contacts in s40 mobiles.
    So i cant get the telephone number.

    Is there any way to get the general contact number from phone contacts in s40 series mobiles?
    Bharath... :)

Similar Threads

  1. Retrieve SIM contacts
    By bhakki in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2010-06-17, 18:16
  2. how to retrieve contacts
    By abhimanyu1 in forum Symbian
    Replies: 2
    Last Post: 2009-08-17, 23:41
  3. How to retrieve contacts from SIM memory.
    By smanikandan14 in forum Symbian
    Replies: 1
    Last Post: 2009-07-14, 08:15
  4. Replies: 5
    Last Post: 2009-06-09, 09:05
  5. [split] Copy contacts to SIM (was Re: Dual SIM devices)
    By jalpesh_patel17 in forum General Development Questions
    Replies: 10
    Last Post: 2008-10-06, 16:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×