某张图片的下载地址为:“http://10.13.73.25:8080/family_image/download.dodownloadfile=mmexport1412173988852.jpg”
private Bitmap getImageBitmap() {
URL imgUrl = null;
Bitmap bitmap = null;
try {
imgUrl = new URL("http://10.13.73.25:8080/family_image/
download.do?downloadfile=mmexport1412173988852.jpg");
HttpURLConnection conn = (HttpURLConnection) imgUrl
.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
报错如下:
10-28 11:01:57.650: W/System.err(6326): java.net.SocketException: socket failed: EACCES (Permission denied)
10-28 11:01:57.650: W/System.err(6326): at libcore.io.IoBridge.socket(IoBridge.java:576)
10-28 11:01:57.650: W/System.err(6326): at java.net.PlainSocketImpl.create(PlainSocketImpl.java:201)
10-28 11:01:57.650: W/System.err(6326): at java.net.Socket.checkOpenAndCreate(Socket.java:664)
10-28 11:01:57.650: W/System.err(6326): at java.net.Socket.connect(Socket.java:808)
10-28 11:01:57.650: W/System.err(6326): at com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
10-28 11:01:57.655: W/System.err(6326): at com.android.okhttp.Connection.connect(Connection.java:101)
10-28 11:01:57.655: W/System.err(6326): at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
10-28 11:01:57.655: W/System.err(6326): at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
10-28 11:01:57.655: W/System.err(6326): at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
10-28 11:01:57.655: W/System.err(6326): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
10-28 11:01:57.655: W/System.err(6326): at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
10-28 11:01:57.655: W/System.err(6326): at com.example.downloadtest.MainActivity.getImageBitmap(MainActivity.java:67)
10-28 11:01:57.655: W/System.err(6326): at com.example.downloadtest.MainActivity.access$0(MainActivity.java:55)
10-28 11:01:57.655: W/System.err(6326): at com.example.downloadtest.MainActivity$1$
1.run(MainActivity.java:40)
10-28 11:01:57.655: W/System.err(6326): at
java.lang.Thread.run(Thread.java:841)
10-28 11:01:57.655: W/System.err(6326): Caused by: libcore.io.ErrnoException: socket failed: EACCES (Permission denied)
10-28 11:01:57.655: W/System.err(6326): at libcore.io.Posix.socket(Native Method)
10-28 11:01:57.655: W/System.err(6326): at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:181)
10-28 11:01:57.655: W/System.err(6326): at libcore.io.IoBridge.socket(IoBridge.java:561)
10-28 11:01:57.655: W/System.err(6326): ... 14 more
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/142053
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.