android如何获取url指定的图片资源
16lz
2021-12-04
// 获取指定路径的图片
public static Bitmap getImage(String urlpath)
throws Exception {
URL url = new URL(urlpath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
Bitmap bitmap = null;
if (conn.getResponseCode() == 200) {
InputStream inputStream = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
}
return bitmap;
}
更多相关文章
- EditText设置不自动获取焦点,点击后才获取,并弹出软键盘
- Android开发学习笔记(十二) 获取系统可用内存
- android获得mac和ip .
- android intent——小白入口
- Android(安卓)USB 开发详解
- Android获取触摸手势实现左右滑动
- 获取apk信息工具(android SDK的aapt工具)
- android中下载文件到sdcard和进度条小结
- android 流量统计实现思路