BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-24-2008, 03:25 AM   #1
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default Access Blackberry Address Book using PIMList

Please Login to Remove!

HI,

I am trying to access the address book using PIM api. I tried using RIM's PIM api but it said, cannot access the methods due to restrictions on the api. Then I tried using javax.microedition.pim.* api. The code is running find and is not reflecting any error or exception.

But for some reason it is not reading the contacts, everytime I try to see the number of elements fetched I get zero as the answer....

Following is the code that I am using for the purpose:

PHP Code:
PIMList list = null;
            
String name="";
            
            try {
                list = (
PIMList)PIM.getInstance().openPIMList(PIM.CONTACT_LISTPIM.READ_ONLY);
                
int field Contact.NAME;
                if(list.
isSupportedField(field)){
                    
int dataType = list.getFieldDataType(field);
                    
Enumeration contactEnum = list.items();
                    
                    
StringBuffer sb = new StringBuffer();
                    while(
contactEnum.hasMoreElements()){tempo=10;
                        
Contact contact = (Contact)contactEnum.nextElement();
                        if(
dataType == Contact.STRING){
                            
v.addElement(contact.getString(field0));
                            
                        }
                        else if(
dataType == Contact.STRING_ARRAY){
                            
Stringxxx91;xxx93; array = contact.getStringArray(field0);
                            
sb.setLength(0);
                            for(
int i=array.lengthi>0i-- ){
                                 
sb.append((arrayxxx91;1xxx93; == null "" : arrayxxx91;1xxx93;) + " ");
                                 
v.addElement(sb.toString());
                            }
                        }
                    }
                }
            } catch (
Exception e) {
                
// TODO: handle exception
                
tempo=3;
            }
            finally{
                if(list !=
null){
                    try {
                        list.
close();
                    } catch (
Exception e) {
                        
// TODO: handle exception
                        
tempo=7;
                    }
                }
            } 
Can anyone please suggest me any thing else...and yeah on more thing the contacts are on the device and not on the memory card incase some one need to know that.....

Hope to hear something gr8....
__________________
Smart People ask for Help!!!
Offline  
Old 07-24-2008, 05:38 AM   #2
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default C'mmon Guys

Quote:
Originally Posted by baran_khan View Post
HI,

I am trying to access the address book using PIM api. I tried using RIM's PIM api but it said, cannot access the methods due to restrictions on the api. Then I tried using javax.microedition.pim.* api. The code is running find and is not reflecting any error or exception.

But for some reason it is not reading the contacts, everytime I try to see the number of elements fetched I get zero as the answer....

Following is the code that I am using for the purpose:

PHP Code:
PIMList list = null;
            
String name="";
            
            try {
                list = (
PIMList)PIM.getInstance().openPIMList(PIM.CONTACT_LISTPIM.READ_ONLY);
                
int field Contact.NAME;
                if(list.
isSupportedField(field)){
                    
int dataType = list.getFieldDataType(field);
                    
Enumeration contactEnum = list.items();
                    
                    
StringBuffer sb = new StringBuffer();
                    while(
contactEnum.hasMoreElements()){tempo=10;
                        
Contact contact = (Contact)contactEnum.nextElement();
                        if(
dataType == Contact.STRING){
                            
v.addElement(contact.getString(field0));
                            
                        }
                        else if(
dataType == Contact.STRING_ARRAY){
                            
Stringxxx91;xxx93; array = contact.getStringArray(field0);
                            
sb.setLength(0);
                            for(
int i=array.lengthi>0i-- ){
                                 
sb.append((arrayxxx91;1xxx93; == null "" : arrayxxx91;1xxx93;) + " ");
                                 
v.addElement(sb.toString());
                            }
                        }
                    }
                }
            } catch (
Exception e) {
                
// TODO: handle exception
                
tempo=3;
            }
            finally{
                if(list !=
null){
                    try {
                        list.
close();
                    } catch (
Exception e) {
                        
// TODO: handle exception
                        
tempo=7;
                    }
                }
            } 
Can anyone please suggest me any thing else...and yeah on more thing the contacts are on the device and not on the memory card incase some one need to know that.....

Hope to hear something gr8....
No reply....????
__________________
Smart People ask for Help!!!
Offline  
Old 07-24-2008, 06:29 AM   #3
arunk
Talking BlackBerry Encyclopedia
 
arunk's Avatar
 
Join Date: Mar 2008
Model: 8310
PIN: N/A
Carrier: Airtel
Posts: 229
Cool

Try this link:


Livelink - Redirection

This is what I am using...
Offline  
Old 07-24-2008, 06:32 AM   #4
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default Thanks

Quote:
Originally Posted by arunk View Post
Try this link:


Livelink - Redirection

This is what I am using...
Thanks a lot dude...I ll try this and let u know ...i hope u dont mind helping me again.....CHEERS!!!!!!!!!!!!!
__________________
Smart People ask for Help!!!
Offline  
Old 07-24-2008, 06:36 AM   #5
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Hi,


This code is using BackBerryContact thing...which jde version are you working on...m on jde 4.2.1 and for some reason I am getthing this error when try to use it...."You cannot access this class due to restrictions on your api..."path to the jar""...

any idea how to sort that thing out....
__________________
Smart People ask for Help!!!
Offline  
Old 07-24-2008, 06:36 AM   #6
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

try this and update it according to your requirements:

Code:
PIMList list = null;
String[] name;

try {
	list = PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);

	Enumeration contactEnum = list.items();


	while(contactEnum.hasMoreElements()){
		//tempo=10;
		StringBuffer sb = new StringBuffer();
		Contact contact = (Contact)contactEnum.nextElement();
		name = contact.getStringArray(Contact.NAME, 0);

		boolean found = false;
		String nameseg;
		if((nameseg = name[Contact.NAME_PREFIX]) != null)
		{
			sb.append(nameseg);
			found = true;
		}
		if((nameseg = name[Contact.NAME_GIVEN]) != null)
		{
			if(found)
			{
				sb.append(' ');
			}
			sb.append(nameseg);
			found = true;
		}
		if((nameseg = name[Contact.NAME_FAMILY]) != null)
		{
			if(found)
			{
				sb.append(' ');
			}
			sb.append(nameseg);
		}
		
		System.out.println("[CONTACT] " + sb.toString());
	}
} catch (Exception e) {
	// TODO: handle exception
	//tempo=3;
}
finally{
	if(list !=null){
		try {
			list.close();
		} catch (Exception e) {
			// TODO: handle exception
			//tempo=7;
		}
	}
}
Offline  
Old 07-24-2008, 06:49 AM   #7
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Hello There,,

Hi, I guess I am making a very silly mistake...here is what I did...

1. I went to the contacts application on the blackberry emulator...and created a couple of contacts there....I can see they are there...

2. Then I created this application to read the address book....Code is already posted...

3. When I executed the code it gave zero contacts fetched...

4. After that I created a few contacts using the code only and not via "Contacts" application.

5. And now I am confused as the code is fetching the ones that I have created and not the ones that were created using the "Contacts" applicatoin.

Please correct if I am mistaking the "Contacts" application as the address book.

This is confusing...where else the address book is???
__________________
Smart People ask for Help!!!
Offline  
Old 07-24-2008, 07:03 AM   #8
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

I hate to admit but I guess I have done the silliest error and have wasted two full days doing that....i made the code for address book and was looking for the things from the contacts...never realized it is not what i need to look for.....damn I am a fool...

Well anyways...yet another thing added to my kitty...m gaining everytime...thanks arunk and my friend Ivanov...i knew u rock and u still are great....next question....why i am not able to use "BlackberryContact" it is giving api restricted error....what is that???
__________________
Smart People ask for Help!!!
Offline  
Old 07-24-2008, 07:05 AM   #9
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

Contacts is the address book. The code I've posted was tested creating the contacts in the BB application and then reading them.

do you call contact.commit(); when adding your own contacts programmatically?
Offline  
Old 07-24-2008, 07:09 AM   #10
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Quote:
Originally Posted by Ivanov View Post
Contacts is the address book. The code I've posted was tested creating the contacts in the BB application and then reading them.

do you call contact.commit(); when adding your own contacts programmatically?
well yes....i did..i can see the contacts created from the address book we get from the calling menu we get once we press the Calling button...and I checked the Contacts application list...I cant see the contacts that I created....how come is it so?
__________________
Smart People ask for Help!!!
Offline  
Old 07-24-2008, 07:44 AM   #11
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Can anyone explain what is this "Restriction on API" error....I cant access "blackberryContact" ...No idea why?
__________________
Smart People ask for Help!!!
Offline  
Old 07-25-2008, 03:19 AM   #12
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

Are you testing on the device or the simulator? BlackberryContact requires code signing.
Offline  
Old 07-25-2008, 03:49 AM   #13
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Quote:
Originally Posted by Ivanov View Post
Are you testing on the device or the simulator? BlackberryContact requires code signing.
Its just the simulator...I'll have to get it signed to test on the device....its just for learning purpose and secondly, don't have a device to test on...

But the issue with me is that I am getting "Restriction on api" error on eclipse(IDE) itself and is not letting me to use it...
__________________
Smart People ask for Help!!!

Last edited by baran_khan; 07-25-2008 at 03:51 AM..
Offline  
Old 07-25-2008, 04:00 PM   #14
cunac
New Member
 
Join Date: Oct 2007
Model: BOLD
PIN: N/A
Carrier: Rogers
Posts: 9
Default

Quote:
Originally Posted by baran_khan View Post
Its just the simulator...I'll have to get it signed to test on the device....its just for learning purpose and secondly, don't have a device to test on...

But the issue with me is that I am getting "Restriction on api" error on eclipse(IDE) itself and is not letting me to use it...
preferences/BlackBerry JDE/Code Signing

check all options
Offline  
Old 07-26-2008, 12:59 AM   #15
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Quote:
Originally Posted by cunac View Post
preferences/BlackBerry JDE/Code Signing

check all options
Man...where were u for past couple of days...u made my job easy...Thanks for ur help.....
__________________
Smart People ask for Help!!!
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty picture

National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty

$690.00



Agilent E1301B Mainframe  9-slots with multimeter, totalizer, and relay muxes picture

Agilent E1301B Mainframe 9-slots with multimeter, totalizer, and relay muxes

$200.00



1 Pcs National Instruments NI PXIe-1071 NI-SD200 Mainframe PXIE-1071 Chassis picture

1 Pcs National Instruments NI PXIe-1071 NI-SD200 Mainframe PXIE-1071 Chassis

$395.00



Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON** picture

Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON**

$150.00



NEWPORT 8800 PHOTONICS TEST SYSTEM MAINFRAME picture

NEWPORT 8800 PHOTONICS TEST SYSTEM MAINFRAME

$499.99



HP - Agilent - Keysight 75000 SERIES C MODEL E8404A High Power VXI Mainframe picture

HP - Agilent - Keysight 75000 SERIES C MODEL E8404A High Power VXI Mainframe

$699.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.