0

I have used two method to load image from remote server. It is working good in version 2.1(Samsung) and 2.3.4(Sony Ericsson Xperia Neo V). But the method is returning null in a samsung mobile V-2.2. The code is given below.

private Drawable ImageOperations(String url, String saveFilename) {
    try {
        String realImageUrl = url + "?email=" + Constants.email
                + "&proc_date=" + Constants.proc_date + "&access_key="
                + Constants.ACCESS_KEY + "&version=1.00";

        String a = realImageUrl.replace("https", "http");

        InputStream is = (InputStream) this.fetch(a);
        Log.e("https,SubString http: ", realImageUrl + "," + a);
        Drawable d = Drawable.createFromStream(is, "saveFilename");

        return d;
    } catch (MalformedURLException e) {
        return null;
    } catch (IOException e) {
        return null;
    }
}

public Object fetch(String address) throws MalformedURLException,
        IOException {
    try {
        URL url = new URL(address);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(),
                url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        url = uri.toURL();
        Log.i("Url:", url + "");
        Object content = url.getContent();

        return content;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
TKumar
  • 818
  • 2
  • 10
  • 35
  • You may want to print the stack trace in your error traps. They only return null but tell you nothing about what error was trapped. – Roy Hinkley Jul 20 '12 at 11:40
  • Actually it is not showing any Error or Exception.when I am hitting the url with web browser there is an image, but this code returning null for android 2.2 . – TKumar Jul 20 '12 at 12:07
  • Try adding these three lines before the getContent method and refactor the getContent method: URLConnection connection; connection = url.openConnection(); connection.connect(); Object content = connection.getContent(); – Roy Hinkley Jul 23 '12 at 13:47

0 Answers0