I have created an android application where image is loading from given url.When I am passing url directly, the image is loading. But image is not loading when I am taking the url inside a string variable and passing that variable . My 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 newUrl=realImageUrl.replace("https", "http");
InputStream is = (InputStream) this.fetch(newUrl);
Log.e("https,SubString http: ",realImageUrl+","+ a);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
return null;
} catch (IOException e) {
return null;
}
}
public Object fetch(String address) throws MalformedURLException,
IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
This code is not working. my new url is newUrl. when I am printing newUrl in my log and giving that url directly instead of newUrl the image is loading.
I have found the solution. I have updated the fetch(String address) method.
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.