Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:44:36+00:00 2026-05-31T15:44:36+00:00

Hi i have a strange problem with HTTP in Android. I’m trying to get

  • 0

Hi i have a strange problem with HTTP in Android.
I’m trying to get a picture from a remote server and display it on the device.
If the picture is a small JPEG, this is not a problem. but if the picture get bigger in size it will not work (only parts of the picture are shown).

Here is my complete demo code:

public class HTTP_testActivity extends Activity {

private ImageView ivPicture;
private Button btGetImage;  


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ivPicture = (ImageView) findViewById(R.id.ivpiture1);
    btGetImage = (Button) findViewById(R.id.btGetPicture1);
    btGetImage.setOnClickListener(new Button.OnClickListener() 
    {
        public void onClick(View arg0) 
        {
            URI uri;
            try {


                uri = new URI("");
                URLConnection connection =  uri.toURL().openConnection();
                connection.setUseCaches(true);
                connection.connect();

                BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
                Log.d("TEST","Length of Input " +bis.available());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Log.d("TEST","Length of Input after wait " +bis.available());
                byte[] data = new byte[640*480*5];
                bis.read(data);
                Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, jdata.length);
                if (bmp != null)
                {
                    ivPicture.setImageBitmap(bmp);
                }
                bis.close();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            Log.d("TEST", e.getMessage());
            e.printStackTrace();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            Log.d("TEST", e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.d("TEST", e.getMessage());
            e.printStackTrace();
        }
        }
    });
}

Can someone see what I’m doing wrong?
What I have figured out so far is: bis.available() returns never more than 65kb. Although the InputStream itself has the right length (seen in the debugger).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:44:38+00:00Added an answer on May 31, 2026 at 3:44 pm

    available()

    will return the number of bytes that con be read from the inputstream without blocking. So it will be return data that could be read from the network without blocking.

    try with:

                InputStream bis = new InputStream(connection.getInputStream());
                Log.d("TEST","Length of Input " +bis.available());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                int read = 0;
                byte[] buffer = new byte[SIZE_OF_IMAGE];
                byte[] inBuff = new byte[32678]
                while ((read = bis.read(inBuff, 0, 32768)) > 0) {
                       // copy in buffer what have been read
                       // from the input stream
                }
    
                // close the is
                Bitmap bmp = BitmapFactory.decodeByteArray(buffer, 0, buffer.length);
    

    obviously is not there are more efficient way to do this but could be an entry point. Let me know if you need more help.

    Edit: of course you have to avoid doing blocking call in the UI thread, as people have suggested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange problem while trying to start JBoss from Eclipse. After starting,
We have very strange problem, one of our applications is continually querying server by
I have a very strange problem with Android animations, I tried many different approaches
I have a strange problem with codeigniter upload class. I use uploadify (http://www.uploadify.com) to
I have a strange problem using a MapView in Android. It works fine until
I have strange problem. I have own remote repository and upload their plugin. Then
I have a strange problem with developing in Scala on Android. I'm using sbt
I have a strange problem on a website I developed ( http://misenplacecatering.it/location ). The
I have strange problem. For a project we are using following cloud hosting. http://www.rackspace.com
I have a strange problem. When I enter my site http://www.dinomuhic.com I sometimes see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.