Hi,
    i want to display an image from URL,i found one example from forum
.but it doing nothing. i m sending the code plz suggest me what to do

package com.example.urlImage;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class urlImage extends Activity {
        
        
        Bitmap bmp;
        URL url = null;
        @Override
        public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        String str="http://www.glamsham.com/images/tv06.jpg";;
        ImageView imView = (ImageView)findViewById(R.id.imview);
        
//url="http://images.orkut.com/orkut/photos/OgAAADG3_VXKdNE9-VI1jHhG_KvV-2H-TBqfxfkp8cgPobEeslgSp1lCpaLixzLb4dUpfZVC2E9A7OX276mu1WTd7asAm1T1UND88tnlTkLBHBCNl_MYo1qh2R28.jpg";;
        try{
        url = new URL(str);
        }
        catch(MalformedURLException e)
        {
                e.printStackTrace();
        }
        try{
                HttpURLConnection conn =  
(HttpURLConnection)url.openConnection();
                conn.setDoInput(true);
                
                conn.connect();
                int length = conn.getContentLength();
                
                int[] bitmapData =new int[length];
                byte[] bitmapData2 =new byte[length];
                
                InputStream is = conn.getInputStream();
                
                bmp = BitmapFactory.decodeStream(is);
                imView.setImageBitmap(bmp);
                } catch (IOException e)
                {
                        e.printStackTrace();
                }
        }
}

        
And my xml file is


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, HTTPImage load test"
/>
<ImageView id="@+id/imview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>


Please suggest me.
Pankaj Nigam
Software Engineer

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to