Retrieving BlackBerryContact phone numbers and the labels then showing it in a dialog to let user to choose.
BlackBerryContact c;
Find out the number of phone numbers saved under a contact
c.countValues(BlackBerryContact.TEL);
Setup variables to hold the numbers and their labels.
phoneNumbers = new String[phoneCount];
labels = new String[phoneCount];
String label = "";
Go through a loop to get the numbers and find out the label
for(int i = 0; i < phoneCount; i++)
{
//Fetch the phone number
String phoneNumber = c.getString(BlackBerryContact.TEL, i);
//Determine the label for that number
if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_MOBILE)
{
label = "mobile";
}
else if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_WORK)
{
label = "work";
}
else if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_HOME)
{
label = "home";
}
//Add the number and label to the array.
phoneNumbers[i] = phoneNumber;
labels[i] = label;
}//end of for loop
Display the number in a Dialog.ask
StringBuffer sb = new StringBuffer();
//If more than one numbers found
if(phoneCount > 1)
{
int choice = Dialog.ask("Which number to use?",labels,0);
if (choice == 0)
{
sb.append(phoneNumbers[0]);
}
else if (choice == 1)
{
sb.append(phoneNumbers[1]);
}
else if (choice == 2)
{
sb.append(phoneNumbers[2]);
}
else if(choice == Dialog.CANCEL)
{
sb.append("CANCEL");
}
}
Wednesday, 29 April 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment