美文网首页
Android之OkHttp怎么接收一个图片

Android之OkHttp怎么接收一个图片

作者: 移动端_小刚哥 | 来源:发表于2020-04-18 12:03 被阅读0次

    废话不多说直接上代码

    Request request = new Request.Builder().url(urlStr).build();
            OkHttpClient client = new OkHttpClient();
            client.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    handler.sendMessage(handler.obtainMessage(1, PCH.mHttpConnectError));
                }
    
                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    InputStream inputStream = response.body().byteStream();
                    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                    yanzhegnmaImageView.setImageBitmap(bitmap);
                    handler.sendMessage(handler.obtainMessage(22, bitmap));
                }
            });
    

    参考文章
    https://blog.csdn.net/hxy19971101/article/details/76177408

    相关文章

      网友评论

          本文标题:Android之OkHttp怎么接收一个图片

          本文链接:https://www.haomeiwen.com/subject/xorvvhtx.html