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
Highlighted
Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel
Accepted Solution

How to get image from URL to display on Blackberry screen

Hi All,

 

   I am creating a Blackberry java application. I have an image url..(like you can say  "http://www.christianfilmdatabase.com/wp-content/uploads/2013/06/Movies.jpg" ) . I have to get this image dynamically and display it on my screen. ...How can i do it... I am posting my code here...

 

 

Bitmap bitmap = Bitmap.getBitmapResource(imageUrl);
					
					Background background = BackgroundFactory.createBitmapBackground(bitmap);

 

Warm Regards,

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get image from URL to display on Blackberry screen

Have you tried searching the forum?  Terms like "download image" will rpobably find some previous Threads that asked similar questions. 

Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: How to get image from URL to display on Blackberry screen

Hi,

  I have written the code for downloading image from a url...(all steps included like getting httpconnection and all....). but i am getting something like this when running my app... "you are attempting to open a secure connection, but the server's certificate is not trusted" I am posting my code used to download image..

Please help me out...

 

 

public static void downloadImage(final String imageUrl) {
		new Thread(new Runnable() {
			public void run() {
				
				ConnectionFactory connectionFactory = new ConnectionFactory();
				
				ConnectionDescriptor connectionDescriptor = connectionFactory.getConnection(imageUrl);
				if (connectionDescriptor != null) {// connect successful
				
					HttpConnection httpConnection = null;
					try {
						httpConnection = (HttpConnection) connectionDescriptor.getConnection();
						
						InputStream in = httpConnection.openInputStream();
						
						byte[] data = IOUtilities.streamToBytes(in);
						
						EncodedImage image = EncodedImage.createEncodedImage(data, 0, data.length);
						
									
						imageBitmap = image.getBitmap();
					} catch (IOException e) {
						synchronized (Application.getEventLock()) {
							
						}
					}finally{
						if(httpConnection != null){
							try {
								
								httpConnection.close();
							} catch (IOException e) {
								e.printStackTrace();
							}
						}
					}
				} else {
					
				}
			}
		}).start();
	}

 

 

 

 

 

Warm regards.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get image from URL to display on Blackberry screen

[ Edited ]

This is not an area of expertise sorry.  But here is my take.

 

I presume you are using an https connection.  This message is appearing because your Server's certificate is not known and the safety of the signing authority can not be determined from the certificates and signing authorities that are included on the BlackBerry device.

 

My advice would be to get your Server folks to buy a proper certificate.

Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: How to get image from URL to display on Blackberry screen

Ok, Thanks for the reply Peter... I am looking into it...

Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: How to get image from URL to display on Blackberry screen

Thanks a lot Peter ...I have now been able to get the images from web and display on the screen...

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get image from URL to display on Blackberry screen

Excellent - can you make this as Solved then?