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

Re: How to download image??

Hello friends,

               Thanks for replying. But I am change URL now I am get small image .png but still I get the exception local maching timeout after 120000,

             tell me friends why the connection is not establish in second time??

Thanks,

ajay

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

Re: How to download image??

Show Your code here.

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

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,

         this is my connection code for fist time when i request by url and i get xml data.

public void checkConnections()
  	 {
    	  try
    	   {       		   
    		    String s1=_username.getText();
   		        String s2=edpass.getText();
   		  		IOThread.baseURL="http:URL"+s1+"/"+s2+"";
    		  	        IOThread.iType=1;
  	                        if(t!=null)
  	                        t=null;
  	                        t=new IOThread();
  	                        t.start();
  	                        t.join();
  	       }
    	     catch(Exception ex)
    	     {
    		    Dialog.alert("Exception"+ex);
    	     }

  	 }

	public void getdata()
  	{
		if(doc!=null)
  		{
  	          doc.getDocumentElement().normalize();
  		  NodeList list[] =new NodeList[19];	   
                  for(int i=1;i<19;i++)	        	 	    
          	     list[i] = doc.getElementsByTagName("*");
             
                  String _element = new String();
                  Node value1,time; 
                             
               
                  for(int k=1;k<19;k++)
                 { 
  	             value1=list[k].item(k).getChildNodes().item(0);
          	     _element=value1.getNodeValue();
          	     strg[k]=_element.toString();
          	  
          	 }

                UiApplication.getUiApplication().pushScreen(new Profile());
         
            }
		      
  		  else
  			Dialog.alert("Invalid user name and password");
  	}

 in that code i get the url of image strg[18] that image i want to show in the profile for that i crreate the new function in profile class. fuction is as bellow.

 public void getimage()
	 {
		 BitmapField bimage=new BitmapField(); 

		 String url1="http://www.imageurlhost.com/images/0pbf6gg8w7rc5mqeh3kd.png";
		 HttpConnection hc=null;
		        DataInputStream dis=null; 
		            try
		            {
		                hc=(HttpConnection)Connector.open(url1);
		                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);
	            }
	      
	 }

 but when the connction is establish for second time i get the time out excetion for

that line

int st=hc.getResponseCode();

 

 

 

 

Regular Contributor
Posts: 59
Registered: ‎07-05-2010
My Device: Blackberry 9800
My Carrier: Airtel

Re: How to download image??

 

String url1="http://www.imageurlhost.com/images/0pbf6gg8w7rc5mqeh3kd.png";

 

 

Without appending "deviceside=" parameter, i don't think you can make any connection with BB device.

Check Peter's sticky network thread for more information.

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

Re: How to download image??

All the things are Right. But server is not responding.

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

Re: How to download image??

What should I do for response? please tell me friend.
Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to download image??

You can try with Appnding the string with

"deviceside=true"

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

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??

Hello ajay,

 

following code is working for me,and was able to show image given in your url give it a try and let me know whether it works or not,

 

 

HttpConnection conn = (HttpConnection) Connector.open("http://www.imageurlhost.com/images/0pbf6gg8w7rc5mqeh3kd.png");

 

responseCode = conn.getResponseCode();

if (responseCode == HttpConnection.HTTP_OK )

{

InputStream in = conn.openInputStream();

 final byte[] output=IOUtilities.streamToBytes(in);

in.close();

IOThread.

EncodedImage image= EncodedImage.createEncodedImage(output, 0,

output.length);

 

BitmapField Bfimage=new BitmapField();

Bfimage.setImage(Address);

 

}

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

Re: How to download image??

have you solved the problem and yes keep mds on.

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

Re: How to download image??

[ Edited ]

hello vijayta bhatt,

                i get responseCode 413.

 

public void getimage()
	 {
		 try
		 {
		      HttpConnection conn = (HttpConnection) Connector.open("http://www.imageurlhost.com/images/0pbf6gg8w7rc5mqeh3kd.png");
             int responseCode = conn.getResponseCode();

		 if (responseCode == HttpConnection.HTTP_OK )

		 {
     	    InputStream in = conn.openInputStream();
		    final byte[] output=IOUtilities.streamToBytes(in);
		    in.close();
    	    EncodedImage image= EncodedImage.createEncodedImage(output, 0,output.length);
           
		    Bfimage.setImage(image);

       }
		 }
		 catch(Exception ex)
		 {
			 Dialog.alert("Exception"+ex);
		 }

 

 

I am using above code.

when i add that image to my scrceen it will show nothing.

            getimage();

            vfm.add(Bfimage);           
            Dialog.alert("str"+Bfimage);

 

in above dialgo it show following data

str   net.rim.device.api.ui.componet.bitmapField@c88c%add

 

tel me where i am wrong??