How to get email2 and mobile2 from phonebook contact - blackberry

Does anyone know how to get email2 and mobile2 from the phonebook? The BlackBerryContact class does not have a constant like BlackBerryContact.EMAIL for email2 and mobile2.

if (contacts.isSupportedField(BlackBerryContact.EMAIL)) {
try {
if (contact.countValues(BlackBerryContact.EMAIL) > 0)
email1 = contact.getString(BlackBerryContact.EMAIL, 0);
System.out.println("Email1 " + email1);
if (contact.countValues(BlackBerryContact.EMAIL) > 1)
email2 = contact.getString(BlackBerryContact.EMAIL, 1);
System.out.println("Email2 " + email2);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(BlackBerryContact.TEL)) {
int count = contact.countValues(BlackBerryContact.TEL);
for (int i = 0; i < count; i++) {
int attribute = contact.getAttributes(BlackBerryContact.TEL, i);
if(attribute == BlackBerryContact.ATTR_MOBILE){
String mobile = contact.getString(BlackBerryContact.TEL,i);
lblField1.setText(mobile);
}
if(attribute == BlackBerryContact.ATTR_HOME){
String home = contact.getString(BlackBerryContact.TEL, i);
lblField2.setText(home);
}
}
}

Related

Spoj brackets segment tree

can anyone help me in my code. I am getting WA and m not able to rectify it plzzz
my code http://ideone.com/DkrwIg
problem link : http://www.spoj.com/problems/BRCKTS/
i am a bit doubtful in my modification function.
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
char str[40010];
struct node
{
int sum;
int minsum;
}tree[1000005];
void build(int id,int l,int r)
{
if(r-l<2)
{
if(str[l] == '(')
{
tree[id].sum = 1;
tree[id].minsum = 1;
}
else
{
tree[id].sum = -1;
tree[id].minsum = -1;
}
return;
}
int mid = (r+l)/2;
build(id*2,l,mid);
build(id*2+1,mid,r);
tree[id].sum = tree[id*2].sum + tree[id*2+1].sum;
tree[id].minsum = min(tree[id*2].minsum,tree[id*2].minsum+tree[id*2+1].minsum);
}
void modify(int index,int id,int l,int r)
{
if(r-l<2)
{
tree[id].sum = tree[id].minsum = -tree[id].sum;
return;
}
int mid = (r+l)/2;
if(index<mid)
modify(index,id*2,l,mid);
else
modify(index,id*2+1,mid,r);
tree[id].sum = tree[id*2].sum + tree[id*2+1].sum;
tree[id].minsum = min(tree[id*2].minsum,tree[id*2].minsum+tree[id*2+1].minsum);
}
int main()
{
int n,k;
int val;
int h = 1;
for(int h=1;h<=10;h++)
{
scanf("%d",&n);
scanf("%s",str);
build(1,0,n);
//cout<<"Test "<<h<<" :"<<endl;
printf("Test %d:\n",h);
//cin>>k;
scanf("%d",&k);
while(k--)
{
cin>>val;
if(!val)
{
if(tree[1].sum == 0 && tree[1].minsum == 0)
{
//cout<<"YES"<<endl;
printf("YES\n");
}
else
{
//cout<<"NO"<<endl;
printf("NO\n");
}
//cout<<tree[1].sum<<"------------"<<tree[1].minsum<<endl;
}
else
{
modify(val-1,1,0,n);
}
}
}
return 0;
}

Stream file from ftp in localhost working in azure no

Hi I using VisualStudio 2012 and I have created web site which reads info (from .csv) from external ftp site. When I running it on local host everything works fine, but then I deployed it to azure web sites it is not working, just show zeros everywhere were should be numbers. (Dont get info from ftp)
public static List<ApiClient.Models.StatsList> GetStatsData(string Ticket, DateTime start, DateTime end, int CampaignId, String CampaignName)
{
//--------------------------------------------------------------------------------------------------------
//Gets stats from GetAdsStats service (included: Banner id, impressions, and clicks)
//--------------------------------------------------------------------------------------------------------
List<ApiClient.Models.StatsList> FullList = GetAdStatsService.GetAdsStats(Ticket, start, end, CampaignId);
List<LikesDislikesList> LikeDislike = new List<LikesDislikesList>();
//--------------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------------
string day;
string month;
if (DateTime.Today.AddDays(-1).Day.ToString().Count() == 1)
{
day = "0" + DateTime.Today.AddDays(-1).Day;
}
else
{
day = DateTime.Today.AddDays(-1).Day.ToString();
}
if (DateTime.Today.Month.ToString().Count() == 1)
{
month = "0" + DateTime.Today.Month;
}
else
{
month = DateTime.Today.Month.ToString();
}
try
{
string uri = "ftp://siteAdres" + CampaignName.Replace(" ", "_") + "_Optimizing_events_" + day + "-" + month + "-" + DateTime.Today.Year + ".csv";
Uri serverUri = new Uri(uri);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return FullList;
}
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential("username", "password");
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader csvStream = new StreamReader(response.GetResponseStream());
//--------------------------------------------------------------------------------------------------------
//Read Likes/Dislikes from csv file stream
//--------------------------------------------------------------------------------------------------------
using (var rd = csvStream)
{
int iname = -1;
int ilikes = -1;
int idislikes = -1;
while (!rd.EndOfStream)
{
var raw = rd.ReadLine().Split((char)9);
if (rd.Peek() == -1)
{
break;
}
if (ilikes == -1 || idislikes == -1)
{
for (int i = 0; i < raw.Length; i++)
{
if (raw[i] == "Event name")
iname = i;
if (raw[i] == "Custom Event 14")
ilikes = i;
if (raw[i] == "Custom Event 15")
{
idislikes = i;
raw = rd.ReadLine().Split((char)9);
}
}
}
else
{
LikeDislike.Add(new LikesDislikesList() { Likes = Convert.ToInt32(raw[ilikes]), Dislikes = Convert.ToInt32(raw[idislikes]), Name = raw[iname] });
}
}
}
response.Close();
}
catch(Exception ex)
{
log4net.Config.XmlConfigurator.Configure();
log.Warn("GetAdStatsService.cs " + ex);
}
//--------------------------------------------------------------------------------------------------------
//Add like/dislike values for certain banners
//--------------------------------------------------------------------------------------------------------
foreach (var element in FullList)
{
foreach (var el in LikeDislike)
{
if (element.name == el.Name)
{
element.Likes = el.Likes;
element.Dislikes = el.Dislikes;
}
}
}
return FullList;
}
}
}
Check FtpWebResponse.StatusCode before calling response.GetResponseStream(). You are probably having come kind of connection error. My guess would be firewall settings on your Azure VM.

open shazam from my blackberry application

I need the code open shazam(other intalled applications in the phone) if its installed.
How can I check whether shazam is installed in a phone,and if installed how can I open it from my app?If any one have idea please help.Thanks in advace.
public static ApplicationDescriptor getApplicationDescriptor(String appName) {
try {
int[] moduleHandles = CodeModuleManager.getModuleHandles();
if (moduleHandles != null && moduleHandles.length > 0) {
for (int i = 0; i < moduleHandles.length; i++) {
ApplicationDescriptor[] applicationDescriptors = CodeModuleManager.getApplicationDescriptors(moduleHandles[i]);
if (applicationDescriptors != null && applicationDescriptors.length > 0) {
for (int j = 0; j < applicationDescriptors.length; j++) {
if (applicationDescriptors[j].getModuleName().toLowerCase().equals(appName.toLowerCase())) {
return applicationDescriptors[j];
}
}
}
}
}
} catch (Exception e) {
System.out.println("error at getApplicationDescriptor" + e);
}
return null;
}
public static int runApplication(String appName) {
int processId = -1;
ApplicationDescriptor appDescriptor = getApplicationDescriptor(appName);
if (appDescriptor != null) {
//is not null Application installed
processId = ApplicationManager.getApplicationManager().getProcessId(appDescriptor);
if (processId == -1) {
// -1 if application has no process (i.e. is not running).
try {
processId = ApplicationManager.getApplicationManager().runApplication(appDescriptor);
} catch (ApplicationManagerException e) {
e.printStackTrace();
}
}
}
return processId;
}
call runApplication like
int pid=-1;
if((pid=runApplication(appName))>-1){
//application running
System.out.println(appName +" runing with process id "+pid);
}

IndexOutOfBoundsException when updating a contact in contact list - Blackberry

Software and Simulator version i am using
Blackberry Smartphone simulator: 2.13.0.65
Blackberry software version 5.0.0_5.0.0.14
I am looking at modifying contacts. Below is the code snippet i am using.
I am getting a IndexOutOfBounds Exception at line
String wtel = blackBerryContact.getString(BlackBerryContact.TEL, supportedAttributes[i]);
Can someone advise what is going wrong here. Following is the code snippet
.....
// Load the addressbook and let the user choose from list of contact
BlackBerryContactList contactList = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE);
PIMItem pimItem = contactList.choose();
BlackBerryContact blackBerryContact = (BlackBerryContact)pimItem;
PIMList pimList = blackBerryContact.getPIMList();
// get the supported attributes for Contact.TEL
int[] supportedAttributes = pimList.getSupportedAttributes(Contact.TEL);
Dialog.alert("Supported Attributes "+supportedAttributes.length); // gives me 8
for (int i=0; i < supportedAttributes.length;i++){
if(blackBerryContact.ATTR_WORK == supportedAttributes[i]){
Dialog.alert("updating Work"); // This alert is shown
Dialog.alert("is supported "+ pimList.isSupportedAttribute(BlackBerryContact.TEL, supportedAttributes[i])+" "+pimList.getAttributeLabel(supportedAttributes[i])); // shows true and work
String wtel = blackBerryContact.getString(BlackBerryContact.TEL, supportedAttributes[i]); // I get a IndexOutOfBounds Exception here
if(wtel != ""){
pimItem.removeValue(BlackBerryContact.TEL, supportedAttributes[i]);
}
pimItem.addString( Contact.TEL, BlackBerryContact.ATTR_WORK, number); // passing the number that has to be updated
if(pimItem.isModified()) {
pimItem.commit();
Dialog.alert("Updated Work Number");
}
}
}
.....
I want to update all the supported attributes for Contact.TEL field
http://www.blackberry.com/developers/docs/5.0.0api/net/rim/blackberry/api/pdap/BlackBerryContact.html
Field Values Per Field Supported Attributes
-----------------------------------------------------------------------------
Contact.TEL 8 Contact.ATTR_WORK, Contact.ATTR_HOME,
Contact.ATTR_MOBILE, Contact.ATTR_PAGER,
Contact.ATTR_FAX, Contact.ATTR_OTHER,
Contact.ATTR_HOME2, Contact.ATTR_WORK2
Reading contact number.
int number = contact.countValues(BlackBerryContact.TEL);
Hashtable multipleContactNumbers = new Hashtable();
for (int i = 0; i < number; i++) {
if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK) {
multipleContactNumbers.put("Work: ", contact.getString(
BlackBerryContact.TEL, i));
} else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK2) {
multipleContactNumbers.put("Work 2: ", contact.getString(
BlackBerryContact.TEL, i));
} else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME) {
multipleContactNumbers.put("Home: ", contact.getString(
BlackBerryContact.TEL, i));
} else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME2) {
multipleContactNumbers.put("Home 2: ", contact.getString(
BlackBerryContact.TEL, i));
} else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
multipleContactNumbers.put("Mobile: ", contact.getString(
BlackBerryContact.TEL, i));
} else if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_OTHER) {
multipleContactNumbers.put("Other: ", contact.getString(
BlackBerryContact.TEL, i));
}
}
Add new contact numbers.
contact.addString(Contact.TEL, Contact.ATTR_HOME, "5555550100");
contact.addString(Contact.TEL, Contact.ATTR_WORK, "5555550103");
contact.addString(Contact.TEL, BlackBerryContact.ATTR_WORK2, "5555550104");
update contact numbers.
int telCount = contact.countValues(Contact.TEL);
for (int i = 0; i < telCount; ++i)
{
int telAttrs = contact.getAttributes(Contact.TEL, i);
if ((telAttrs & Contact.ATTR_MOBILE) != 0)
{
contact.setString(Contact.TEL, i, Contact.ATTR_MOBILE, "5555550109");
break;
}
}

How to populate a Listfield with results from a Autocomplete field using Blackberry API

How can we populate a Listfield in blackberry with results from a Autocomplete field using Blackberry API(JDE 5)
This is the code to get Contacts, returns a vector containing string array..
contact[0] is name, contact[1] is email and contact[2] is contact number..
read elements from vector and set autocompleteField:Example: http://docs.blackberry.com/en/developers/deliverables/18125/Autocomplete_text_field_1200231_11.jsp
private Vector getContacts() {
Vector result = new Vector();
try {
BlackBerryContactList contactList = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
Enumeration enumx = contactList.items();
while (enumx.hasMoreElements()) {
BlackBerryContact c = (BlackBerryContact) enumx.nextElement();
String[] contact = new String[3];
if (contactList.isSupportedField(BlackBerryContact.NAME)) {
String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
String firstName = name[Contact.NAME_GIVEN];
String lastName = name[Contact.NAME_FAMILY];
System.out.println("this is contact..........." + firstName);
contact[0] = firstName + " " + lastName;
}
if (contactList.isSupportedField(BlackBerryContact.EMAIL)) {
StringBuffer emails = new StringBuffer();
int emailCount = c.countValues(BlackBerryContact.EMAIL);
for (int i = 0; i < emailCount; i++) {
String email = c.getString(BlackBerryContact.EMAIL, i);
if (email != null) {
emails.append(email.trim());
emails.append("; ");
}
}
contact[1] = emails.toString();
}
if ((contactList.isSupportedField(BlackBerryContact.TEL)) && (c.countValues(BlackBerryContact.TEL) > 0)) {
int numValues = 0;
try {
numValues = c.countValues(BlackBerryContact.TEL);
} catch (Exception localException) {
}
String mobileNumber = "";
String homeNumber = "";
String workNumber = "";
for (int i = 0; i < numValues; ++i) {
if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK)
workNumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME)
homeNumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE)
mobileNumber = c.getString(BlackBerryContact.TEL, i);
}
if (!mobileNumber.equalsIgnoreCase(""))
contact[2] = mobileNumber.toString();
else if (!homeNumber.equalsIgnoreCase(""))
contact[2] = homeNumber.toString();
else if (!workNumber.equalsIgnoreCase(""))
contact[2] = workNumber.toString();
}
result.addElement(contact);
}
} catch (PIMException ex) {
ex.printStackTrace();
}
return result;
}
There's a sample app provided with the developer tools that demonstrates the use of this field. From your developer tools directory go to samples/com/rim/samples/device/ui/autocompletefielddemo and you'll see the AutoCompleteFieldDemo.java app.

Resources