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
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
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
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
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:
Cut & Paste your Contact reading code here.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) { } } }
Thanks,
Ekta
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
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
Put some alerts for testing after each field and you will get where it stuck's.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
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.
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
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... :)