这是一个创建于 3687 天前的主题,其中的信息可能已经有所发展或是发生改变。
某张图片的下载地址为:“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
|
|
2
StackGao 2014-10-28 11:15:44 +08:00 1
<uses-permission android:name="android.permission.INTERNET"/>
|