Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
125 views
Welcome To Ask or Share your Answers For Others

1 Answer

connection = url.openConnection();
connection.connect(); // <-- does it work if you add this line?
Object response = connection.getContent();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...