I'm facing this issue only with this url always BitmapFactory.decodeStream
failed to decode bufferedInputStream
I think the problem is actually from connection request but It's been two days and I'm trying to fix the issue..
Any simple help would be very helpful..
My code:
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> Log.d(getClass().getName(), "OkHttp: " + message));
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.addInterceptor(logging);
Request request = new Request.Builder().url("https://manga.ae/cdn/cdn1/2338/0029/15.jpg")
.addHeader("Referer","https://mngaar.com/")
.addHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36")
.addHeader("Content-Type", "image/jpeg")
.build();
client.build().newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.i("Tag", "error" + e.getMessage());
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
runOnUiThread(new Runnable() {
@Override
public void run() {
ResponseBody in = response.body();
InputStream inputStream = in.byteStream();
Log.i("inputStream", "inputstream value = " + inputStream);
try {
Log.i("responseBody", "ResponseBody value = " + in.string());
} catch (IOException e) {
e.printStackTrace();
}
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
Bitmap bitmap = BitmapFactory.decodeStream(bufferedInputStream);
Log.i("bitmap", "bitmap value = " + bitmap);
imageView.setImageBitmap(bitmap);
}
});
}
});
LogCat:
OkHttp: <-- 200 https://manga.ae/cdn/cdn1/2338/0029/15.jpg (1497ms)
OkHttp: date: Thu, 15 Jul 2021 11:11:10 GMT
OkHttp: content-type: image/jpeg
OkHttp: content-length: 144200
OkHttp: x-frame-options: SAMEORIGIN
OkHttp: last-modified: Fri, 23 Dec 2016 15:02:29 GMT
OkHttp: etag: "23348-54454acb46b40"
OkHttp: x-xss-protection: 1; mode=block
OkHttp: x-frame-options: SAMEORIGIN
OkHttp: x-content-type-options: nosniff
OkHttp: cache-control: max-age=259200
OkHttp: cf-cache-status: HIT
OkHttp: age: 5953
OkHttp: accept-ranges: bytes
D/com.example.newbagdad.MainActivity: OkHttp: expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
OkHttp: report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=2hhpsuHQMTAPG04De4208d2yzHTbJnY5dki9YYGFECczz%2FlOcs9mxR9jX79eq9UOlxUuNAupDpYzPdOX0YCmytNbNI9K1ALuBjt7616iUwvuAhvJE%2B6QLvpG0g%3D%3D"}],"group":"cf-nel","max_age":604800}
OkHttp: nel: {"report_to":"cf-nel","max_age":604800}
OkHttp: vary: Accept-Encoding
OkHttp: server: cloudflare
OkHttp: cf-ray: 66f28c6d391b082c-CDG
OkHttp: alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400
D/com.example.newbagdad.MainActivity: OkHttp:
OkHttp: <-- END HTTP (binary 144200-byte body omitted)
I/inputStream: inputstream value = 144200
D/skia: --- codec->getAndroidPixels() failed.
I/bitmap: bitmap value = null