BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-24-2008, 04:25 AM   #1 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 06:38 AM   #2 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 07:29 AM   #3 (permalink)
Talking BlackBerry Encyclopedia
 
arunk's Avatar
 
Join Date: Mar 2008
Model: 8310
PIN: N/A
Carrier: Airtel
Posts: 229
Post Thanks: 0
Thanked 0 Times in 0 Posts
Cool

Try this link:


Livelink - Redirection

This is what I am using...
Offline  
Old 07-24-2008, 07:32 AM   #4 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 07:36 AM   #5 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 07:36 AM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 07:49 AM   #7 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 08:03 AM   #8 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 08:05 AM   #9 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 08:09 AM   #10 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 08:44 AM   #11 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 04:19 AM   #12 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you testing on the device or the simulator? BlackberryContact requires code signing.
Offline  
Old 07-25-2008, 04:49 AM   #13 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 04:51 AM.
Offline  
Old 07-25-2008, 05:00 PM   #14 (permalink)
New Member
 
Join Date: Oct 2007
Model: BOLD
PIN: N/A
Carrier: Rogers
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
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, 01:59 AM   #15 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
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


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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