public static Vector retrieveContactInfo()
{
Vector vContactInfo = new Vector();
//Check that PIM Optional Package is available
String pimVersion = System.getProperty("microedition.pim.version");
if(pimVersion == null)
return null;
else
{
PIM pim = PIM.getInstance();
ContactList contactList = null;
try
{
contactList = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
if(contactList == null)
{
return null;
}
Enumeration clEnum = contactList.items();
while(clEnum.hasMoreElements())
{
Contact contact = (Contact) clEnum.nextElement();
String name = "";
try
{
//if(contactList.isSupportedField(Contact.FORMATTED_NAME))
{
name = contact.getString(Contact.FORMATTED_NAME, 0);
}
}
catch(Exception ex) //An unexpected error occurred while reading the contact name.
{
continue;
}
if(!contactList.isSupportedField(Contact.TEL))
{
continue;
}
int noOfPhones = contact.countValues(Contact.TEL);
Vector vTelInfo = new Vector();
for(int i = 0; i < contactattribute =" contact.getAttributes(Contact.TEL," number =" contact.getString(Contact.TEL," teltype = "" contactattribute ="="" teltype = "Home" contactattribute ="="" teltype = "Mobile" contactattribute ="="" teltype = "Work" contactattribute ="="" teltype = "Other" contactattribute ="="" teltype = "Pager" contactattribute ="="" teltype = "General"> 0)
{
vContactInfo.addElement(new ContactInfo(name, vTelInfo));
}
}
}
catch (PIMException ex)
{
return null;
}
catch (SecurityException ex)
{
return null;
}
return vContactInfo;
}
This is mainly focused on the key to mobile application development using android technology. Here I am putting source code as posts that I created for my needs, and I want to share my knowledge to others who is facing any problem related with same topic.
Sunday, March 28, 2010
Thursday, March 4, 2010
String manipulation, split string with specified delimeter and store into vector
public class StringManip {
public static Vector split(String str, final String delim, boolean discardEndData) {
Vector vComponents = new Vector();
int index = 0;
while (index < str.length()) {
int newIndex = str.indexOf(delim, index);
if (newIndex > 0) {
vComponents.addElement(str.substring(index, newIndex));
} else {
if (discardEndData == false) {
vComponents.addElement(str.substring(index));
}
break;
}
index = newIndex + delim.length();
}
return vComponents;
}
example :-
Vector v = StringManip.split("aaa,aaaa,aaa,aa" , ",", false);
public static Vector split(String str, final String delim, boolean discardEndData) {
Vector vComponents = new Vector();
int index = 0;
while (index < str.length()) {
int newIndex = str.indexOf(delim, index);
if (newIndex > 0) {
vComponents.addElement(str.substring(index, newIndex));
} else {
if (discardEndData == false) {
vComponents.addElement(str.substring(index));
}
break;
}
index = newIndex + delim.length();
}
return vComponents;
}
example :-
Vector v = StringManip.split("aaa,aaaa,aaa,aa" , ",", false);
Subscribe to:
Posts (Atom)