我使用了两种方法从远程服务器加载图像。它在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;
}