Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
divit
Posts: 115
Registered: 10-24-2009

How to Retrive contact numbers in Blackberry

Hi all

 I am the beginner so please can any one help to retrive the contact in blackberry .

i know there is a api net.rim.blackberry.api.pdap but i dnt know  how to use it . it have worked on retriving contact in j2me using PIM .


please if u have any sample code to retrive the contact please share it


Regards

Divya

 

Please use plain text.
Developer
girishthakr
Posts: 232
Registered: 12-15-2008
My Carrier: Vodafone India

Re: How to Retrive contact numbers in Blackberry

 

Hope this will work....       Here I m invoking Contact List  and on click on any Contact   I m getting its MOBILE number..

 

**********************************************

 

 final PIM pim = PIM.getInstance(); 

                BlackBerryContactList contactList = null;

 

              String number = "";

 

         //*                     

           try{

           contactList = (BlackBerryContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);          ////   This will ///invoke ur contact list

            }catch(Exception e)

            {System.out.println("Error  : : "+e);}

 

 

              final PIMItem selectedItem =  contactList.choose();     

                         try{ 

                           int[] fieldIds = selectedItem.getFields();

                           int id;     

 

         for (int atrCount = 0;atrCount < selectedItem.countValues(Contact.TEL); ++atrCount)

          {

            switch(selectedItem.getAttributes(Contact.TEL, atrCount))

            {

              case Contact.ATTR_MOBILE:

             String value =  selectedItem.getString(Contact.TEL, atrCount);

               System.out.println("GGGGGGGGGGGggg ot it :: "+value);

               number = value;

 

                break;

 

 

            }

          }

 

           if(number != "")

               {System.out.println("Innnnn");}

               else

               {

               System.out.println("Outttttt");

               Dialog.alert("OOPS not a mobile number!!");

               System.out.println("Outttttt 1231231212122");

            }

 

 

                           }    catch(Exception e)

                           {System.out.println("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE "+e);}

 

 

                                  if (selectedItem instanceof Contact)

                                   {        System.out.println("User selected a Contact: " +selectedItem );  

                                   } 

                                   else if (selectedItem instanceof BlackBerryContactGroup) 

                                   {        System.out.println("User selected a BlackBerryContactGroup: " + selectedItem);    }

                                   else

                                    {        // at this point we can assume that selectedItem==null, indicating user cancelled  

                                         System.out.println("User cancelled the selection");    }

 

 

***************************************************

 

 

Thnx....

Please use plain text.
Developer
divit
Posts: 115
Registered: 10-24-2009

Re: How to Retrive contact numbers in Blackberry

I want to display the retrieved contact on List Field is it possible ?

How can i do it ??

 

Please use plain text.
Developer
divit
Posts: 115
Registered: 10-24-2009

Re: How to Retrive contact numbers in Blackberry

Is it possible to retrieve the contacts without signing the certificate just for testing purpose 

Please use plain text.
Developer
kanaksony
Posts: 373
Registered: 04-11-2009

Re: How to Retrive contact numbers in Blackberry

No, its not possible.You can test on the Simulator only without signing.

Regards,
Kanak Sony
---------------------------------------------------------------------------------
Please use plain text.
Developer
divit
Posts: 115
Registered: 10-24-2009

Re: How to Retrive contact numbers in Blackberry

ok thanks, but i want to display the retrieved contacts along with contact name and contact number on the listfield how it is possible???

 

and i have tried the above code but i am getting exception "Push modal screen called by non -event thread"

 

please help me  

Please use plain text.
Developer
divit
Posts: 115
Registered: 10-24-2009

Re: How to Retrive contact numbers in Blackberry

[ Edited ]

and i have tried the above code but i am getting exception "Push modal screen called by non -event thread" ,

but no errors but its not retrieving the contacts i am writing the above code in the constructor of my class (displaycontacts this extends MainScreen --this class displaycontatcs is called by main thread  )

 

 

 

class pimaccess  extends UiApplication {
    
	pimaccess() {
        displaycontacts  homeScreen = new displaycontacts ();
        pushScreen(displaycontacts );
    }
    
     public static void main(String[] args){       
    	 pimaccess myApp = new pimaccess();
       myApp.enterEventDispatcher();
    }
} 

class displaycontacts  extends MainScreen    {
    
        private MyObjectListField list;  
  private String[] phnum;

displaycontacts ()
{
//here i am writing the above code (retrives the contact)
//inside the for loop is am storing the telephonenumber in string array phnum[ ]
//list.set(phnum);
//this.add(list);

private class MyObjectListField extends ObjectListField {
        
   public void drawListRow(ListField listField, Graphics graphics, 
                int index, int y, int width) {
         
             graphics.drawText("- " + phnum[index], 0,
                 y, DrawStyle.ELLIPSIS, width);
      
        }
    };

}
 

 

 

 Is it correct please help me??

 

 


 

Please use plain text.