09-15-2010 03:25 AM
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/qjm33ojz1f1ugne
how I show on profile?? Please help me friends.
Thanks,
ajay
Solved! Go to Solution.
09-15-2010 03:35 AM
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.
09-15-2010 03:49 AM
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.getResponseMess age()); 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.
09-15-2010 03:50 AM
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
09-15-2010 03:54 AM
is the above link you are using to get profile picture?
09-15-2010 03:59 AM
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.
09-15-2010 05:07 AM
is your problem solved?
09-15-2010 05:45 AM
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
09-15-2010 06:06 AM
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/qjm33ojz1f1ugne ygt0.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.getResponseMess age());
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
09-15-2010 06:10 AM
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.