我使用了两种方法从远程服务器加载图像。它在 2.1(三星)和 2.3.4(索尼爱立信 Xperia Neo V)版本中运行良好。但是该方法在三星移动 V-2.2 中返回 null。代码如下。
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;
}