Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 415
Registered: ‎07-28-2010
My Device: 8000
My Carrier: hi
Accepted Solution

How to download image??

Hello friends,

                      I am new in blackberry development. My http connection is establish. I get one XML file in which all profile information and one profile image is there. I know how to work with profile information.

I don't how I show the profile image on profile. Please tell me how I show profile image??

                    I get the link like


http://www.imageurlhost.com/images/qjm33ojz1f1ugneygt0.jpg

 

how I show on profile?? Please help me friends.

 

Thanks,

ajay

Trusted Contributor
Posts: 146
Registered: ‎03-22-2010
My Device: Not Specified

Re: How to download image??

can you please tell me whether you are having problem in downloading profile picture or showing that profile picture on screen.

Also let me know whether you are getting profile picture in bytes.

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to download image??

 

String url="Enter URl Here of Image.";
 HttpConnection hc=null; DataInputStream dis=null;
            try { hc=(HttpConnection)Connector.open(url); hc.setRequestMethod(HttpConnection.GET); int st=hc.getResponseCode(); int len=(int)hc.getLength(); System.out.println("Code==>"+hc.getResponseCode()); System.out.println("Message==>"+hc.getResponseMessage()); byte bts[]=new byte[len]; dis=new DataInputStream(hc.openInputStream()); dis.readFully(bts); image=EncodedImage.createEncodedImage(bts,0,len); dis.close(); hc.close(); }catch(Exception e){}

 And now Using BitmapField you can show the Image on screen.

------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

 

Developer
Posts: 415
Registered: ‎07-28-2010
My Device: 8000
My Carrier: hi

Re: How to download image??

Hello friend,

                      Thanks for replying me. I get the image link from server. But don't know how to show on profile??

                    I am creating bitmap field but when assign that link to bitmap field it give null pointer exception means that assignment is wrong. Please tell me how I assign that link ??

                   fist I download that image or I can assigning that link directly to the bitmap field??  If I download that image I have to store that image but I just want to view that image.

  thanks

 ajay

Trusted Contributor
Posts: 146
Registered: ‎03-22-2010
My Device: Not Specified

Re: How to download image??

is the above link you are using to get profile picture?

 

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to download image??

First U have to download Image. then Use the BitmapField to show on the screen.

 

            EncodedImage image1="call the above code here."//Make a Method of above code
            BitmapField bimage=new BitmapField();   
            bimage.setImage(image1);
            add(bimage);
------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.


Trusted Contributor
Posts: 146
Registered: ‎03-22-2010
My Device: Not Specified

Re: How to download image??

is your problem solved?

Developer
Posts: 415
Registered: ‎07-28-2010
My Device: 8000
My Carrier: hi

Re: How to download image??

NO. When I write that code than it will create new connection to the server. Than I get timeout error of first connection.

       I create the connection in first time. But when I try that for second link it give me timeout exception.

Thanks

ajay

Developer
Posts: 415
Registered: ‎07-28-2010
My Device: 8000
My Carrier: hi

Re: How to download image??

Hello friends,

                     when I enter valid user id and password than I get XML format file. I read the data from that XML format data. But when I get the link of image in that file. When I want to download that image I am creating new connection to there server. But when I connect to that server second time I get response code 0. I attaching my code when I connect to there server second time. 

public void getimage()
	 {
		 BitmapField bimage=new BitmapField(); 
   	    
     	   
	        String url="http://www.imageurlhost.com/images/qjm33ojz1f1ugneygt0.jpg";
	        HttpConnection hc=null;
	        DataInputStream dis=null; 
	            try
	            {
	                hc=(HttpConnection)Connector.open(url);
	                hc.setRequestMethod(HttpConnection.GET);
	                int st=hc.getResponseCode();
	                int len=(int)hc.getLength();
	                  System.out.println("Code==>"+hc.getResponseCode());
	                System.out.println("Message==>"+hc.getResponseMessage());
	                byte bts[]=new byte[len];
	                dis=new DataInputStream(hc.openInputStream());
	                dis.readFully(bts);                
	              EncodedImage image=EncodedImage.createEncodedImage(bts,0,len);
	              
               bimage.setImage(image);
               add(bimage);
	              dis.close();
	              hc.close();       
	              
	            }
	            catch(Exception e)
	            {
	            	Dialog.alert("Exception"+e);
	            }
	      
	 }

 

 

 int st=hc.getResponseCode();

 

at that line i get Responsecode 0.

please tel me where i am wrong??

thanks

ajay

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to download image??

This image on this URL is too big.

try for small Image.

------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.