指定された URL から画像が読み込まれる Android アプリケーションを作成しました。URL を直接渡すと、画像が読み込まれます。しかし、文字列変数内の URL を取得してその変数を渡すと、画像が読み込まれません。私のコードを以下に示します。
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;
}
このコードは機能していません。私の新しい URL は newUrl です。ログに newUrl を出力し、newUrl の代わりにその URL を直接指定すると、画像が読み込まれます。