public Bitmap getWebBitmap(String imgUrl) {        Bitmap bitmap =null;        try {            InputStream inputStream = null;            URL url;            url = new URL(imgUrl);            if (url != null) {                // 打开连接                HttpURLConnection httpURLConnection = (HttpURLConnection) url                        .openConnection();                httpURLConnection.setConnectTimeout(3000);// 设置网络连接超时的时间为3秒                httpURLConnection.setDoInput(true); // 打开输入流                int responseCode = httpURLConnection.getResponseCode(); // 获取服务器响应值                if (responseCode == HttpURLConnection.HTTP_OK) { // 正常连接                    inputStream = httpURLConnection.getInputStream(); // 获取输入流                }                bitmap = BitmapFactory.decodeStream(inputStream);            }        } catch (Exception e) {            e.printStackTrace();        }        return bitmap;    }

最好得到了Bitmap就可随便使用了。

需要注意的是,但凡要联网的:1、都要设置访问权;2、放到线程中去处理

<uses-permission android:name="android.permission.INTERNET"/>

更多相关文章

  1. Android开发学习——android与服务器端数据交互
  2. android listview 与 一般多线程配合产生的错误,资料汇总
  3. android 用post方式上传图片到服务器
  4. Android/iso客户端与服务器安全通信(Oauth2.0+3DES+RSA)
  5. android 与 服务器通信
  6. 文件多线程下载实现
  7. android使用多线程处理
  8. Android中通过其他线程更新主线程UI
  9. Android 之retrofit2 之 @body上传服务器是空值

随机推荐

  1. Android——属性动画(Property Animation)
  2. Android SharedPreferences保存登录状态
  3. 编译FFMpeg的Android版本,并整合到android
  4. android 访问网络不能在主线程中进行以及
  5. Android:TextUtils类介绍以及常见使用
  6. Android(安卓)studio 中关于模拟器的 / d
  7. android仿iPhone滚轮控件实现及源码分析(
  8. RK3288 android 5.1 HDMI 喇叭同时输出声
  9. Ant编译android工程之环境搭建
  10. 植物大战僵尸2 Android破解版,免费买道具