Android之OkHttp怎么接收一个图片

2020-04-18  本文已影响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

上一篇下一篇

猜你喜欢

热点阅读