How to add mobile number to blackberry contact editor in programatically from my blackberry application?
I am developing one application in that i have contact details ,when i click the contact number it will ask some option like call or sms or add to phone contact. I implemented call and sms, But when am trying to implement add number 开发者_JS百科,name ,email in to the phone contact am getting struggle. the below code am used for add contact
try
{
ContactList contacts = null;
try {
contacts = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
} catch (PIMException e) {
// An error occurred
return;
}
Contact contact = contacts.createContact();
String[] name = new String[ contacts.stringArraySize( Contact.NAME) ];
name[Contact.NAME_GIVEN] = "Kate";
name[Contact.NAME_FAMILY] = "Turner";
contact.addStringArray(Contact.NAME, Contact.ATTR_NONE,name);
contact.addString(Contact.EMAIL, Contact.ATTR_NONE, emailAddressTo);
contact.addString(Contact.TEL,Contact.ATTR_NONE,"6776787"//this for voice call number.
AddressBookArguments entry = new AddressBookArguments(AddressBookArguments.ARG_NEW, contact);
Invoke.invokeApplication(Invoke.APP_TYPE_ADDRESSBOOK, entry);
}
catch (Throwable t)
{
}
}
This above code work fine but when am trying to add mobile number like this
contact.addString(Contact.ATTR_MOBILE,Contact.ATTR_NONE,"mobile Number");
am getting exception Illegal argument Exception, I don't know how to add the mobile number here,Can anyone help me to solve this?
You can do like this,
if (contacts.isSupportedField(Contact.TEL)) {
contact.addString(Contact.TEL, Contact.ATTR_MOBILE, "1234567890");
}
See this IBM developerWorks article for more info:
Develop mobile apps with Personal Information Management
精彩评论