Android之OkHttp怎么接收一个图片

废话不多说直接上代码

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怎么接收一个图片)