Androidアプリケーションで画像を表示する必要があります。問題は、この画像をオンラインのどこかから取得したいということです。URLは次のようになります。
http://www.mydomain.com/hello world image.png
ご覧のとおり、画像名にいくつかのスペースが含まれています。コードを実行するたびに、FileNotFoundの例外が表示されます。そして何も起こりません。
以下は私のコードです
String imagePathCon = "hello world image.png";
String imagePath = "http://www.mydomain.com/" + imagePathCon;
try {
URL url;
url = new URL(imagePath);
// url = new URL("http://www.azuma-kinba.com/wp-content/uploads/2012/05/Android-Make-Google-Loss-in-2010.png");
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src");
im.setImageDrawable(d);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
スペースを「+」に置き換えるために使用しますが、何も起こりません。