-1

I use the following method to get a bitmap input stream:

    private InputStream getInputStream(String urlString) throws MalformedURLException, IOException {
    URL url = new URL(urlString);
    URLConnection connection;
    connection = url.openConnection();
    //connection.setUseCaches(true); 
    Object response = connection.getContent();
    if (!(response instanceof InputStream))
        throw new IOException("URLConnection response is not instanceof InputStream");

    return (InputStream)response;
}

It works great on Android 2.3 (GalaxyS2) but on Android 2.2 (GalaxyS) response = null.

The remote url is a bitmap.

Any ideas?

Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130

1 Answers1

4
connection = url.openConnection();
connection.connect(); // <-- does it work if you add this line?
Object response = connection.getContent();
cwin
  • 956
  • 1
  • 7
  • 14
  • 1
    I had a similar problem: While InputStream `stream = (InputStream) url.getContent()` works well on Android 4+, Android 2.2 did return null *randomly*. Your solution works on both. – sulai Dec 18 '12 at 16:01