BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-18-2009, 10:20 PM   #1 (permalink)
New Member
 
Join Date: Oct 2009
Model: 8820
PIN: N/A
Carrier: abc
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How can get image by url

Please Login to Remove!

How can get image by url? I use httpConnection to get image but have an error. When i check responseCode, is alway is 0 so connect is fail.
Quote:
HttpConnection connection = null;
InputStream inputStream = null;
Photoshow aShow = (Photoshow)saveList.elementAt(first);
String url = aShow.getIconURL();
String head = url.substring(0, 45);
String end = url.substring(45, url.length());
url = head + "w50/h50/" + end;
rawResponse = new StringBuffer();
try
{
connection = (HttpConnection) Connector.open(url);

int responseCode = connection.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK)
{
throw new IOException("HTTP response code: "
+ responseCode);
}

inputStream = connection.openInputStream();
byte[] responseData = new byte[10000];
int length = 0;
while (-1 != (length = inputStream.read(responseData)))
{
rawResponse.append(new String(responseData, 0, length));
}


}
catch (final Exception ex)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
image[first].callback("Exception (" + ex.getClass() + "): " + ex.getMessage());
}
});
}
Offline  
Old 12-18-2009, 10:37 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Quote:
Originally Posted by phucnhfpt View Post
How can get image by url? I use httpConnection to get image but have an error. When i check responseCode, is alway is 0 so connect is fail.
Code:
HttpConnection connection = null;
InputStream inputStream = null;
Photoshow aShow = (Photoshow)saveList.elementAt(first);
String url = aShow.getIconURL();
String head = url.substring(0, 45);
String end = url.substring(45, url.length());
url = head + "w50/h50/" + end;
rawResponse = new StringBuffer();
try
{
   connection = (HttpConnection) Connector.open(url);

   int responseCode = connection.getResponseCode();
   if (responseCode != HttpConnection.HTTP_OK)
   {
      throw new IOException("HTTP response code: " + responseCode);
   }

   inputStream = connection.openInputStream();
   byte[] responseData = new byte[10000];
   int length = 0;
   while (-1 != (length = inputStream.read(responseData)))
   {
      rawResponse.append(new String(responseData, 0, length));
   }


}
catch (final Exception ex)
{
   UiApplication.getUiApplication().invokeLater(new Runnable()
   {
      public void run()
      {
          image[first].callback("Exception (" + ex.getClass() + "): " + ex.getMessage());
      }
   });
}
What is a Photoshow? More specifically what format of URL does Photoshow.getIconURL() return?
__________________
My other Blackberry is a PlayBook.
Offline  
Old 12-18-2009, 10:54 PM   #3 (permalink)
New Member
 
Join Date: Oct 2009
Model: 8820
PIN: N/A
Carrier: abc
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The iconURL return a url of jpg image. Photoshow is an object i created to manage photo. The url is does not have any problem and i checked it can load by Browser of 8820. Sr i can post url for you to see.
For more detail, with this code i can run on Simulator 8120 without any problem while i built on 8120 device no image can load. And i try to run on 8820 simulator, this is same when i run on 8120 device.
Offline  
Old 12-18-2009, 11:12 PM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

What type of conneciton do you think you are making? Are you placing any conneciton parameter suffix on the URL? Have you set you APN info in device options?

On the BB, you cannot just connect to a URL. You need to understand what type of connection you are making, and craft your parameters accordingly. The simulator masks this complexity, because you can connect with no parameter (when running MDS-CS), or with just ";deviceside=true", (when making a direct TCP connection).

Please use the search button and do some research. This issue is posted almost every day on this forum.
Offline  
Old 12-18-2009, 11:25 PM   #5 (permalink)
New Member
 
Join Date: Oct 2009
Model: 8820
PIN: N/A
Carrier: abc
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

My url likes this : view.ds7.photoshow.com/media/sc3Vp9nf/w50/h50/eca217721988f2ff6360398b545d04bc.jpg . I've cut http :// in the header.

I don't understand something you said example APN. So can you send to me a link with similar problem? I don't know the keywords that can search my problem. Sorry because i'm new BB developer.

Please help!

Last edited by phucnhfpt : 12-18-2009 at 11:35 PM.
Offline  
Old 12-19-2009, 08:35 AM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

The best information I've found are in the devlopers' videos. The latest network transport video is Media Library
__________________
My other Blackberry is a PlayBook.
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.