• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Image view not rendering the images from share point server

imgview = view.findViewById(R.id.imgview);
imgview.setImageBitmap(loadImage());

private Bitmap loadImage(){
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder()
.url("https://domainname/sites/iConnect/Lists/FeedList/Attachments/1133/2996AnuragModi.jpg")
.addHeader("Authorization","Bearer".concat(" ").concat(LoginRedirectActivity.authToken) ).build();

okHttpClient.newCall(request).enqueue(new Callback() {
@override
public void onFailure(Call call, IOException e) {
System.out.println(e.getMessage());
}

@override
public void onResponse(Call call, Response response) throws IOException {

byte[] bytes = response.body().bytes();
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);


}
});
return bitmap;
}

Method 2:

Picasso.get().load(imgurl).into(holder.userimg);

Method 3:

using Volley lib:

RequestQueue queue = Volley.newRequestQueue(context);
ImageRequest imgrequest = new ImageRequest(imgurl, new com.android.volley.Response.Listener<Bitmap>() {
@override
public void onResponse(Bitmap response) {
if(response!=null)
{
holder.userimg.setImageBitmap(response);
}

}
}, 100, 100, ImageView.ScaleType.CENTER_CROP, Bitmap.Config.ARGB_8888, new com.android.volley.Response.ErrorListener() {
@override
public void onErrorResponse(VolleyError error) {
Log.e("Image error", error.toString());
Log.d("Exception", error.toString());
String volleyerror;
NetworkResponse response = error.networkResponse;
try {
String res = new String(response.data,
"utf-8");
Log.d("errorresponse", res);
// Now you can use any deserializer to make sense of data
JSONObject obj = new JSONObject(res);
} catch (UnsupportedEncodingException e1) {
// Couldn't properly decode data to string
e1.printStackTrace();
} catch (JSONException e2) {
// returned data is not JSONObject?
e2.printStackTrace();
}
if (error instanceof NetworkError) {
volleyerror = "Network Error";

} else if (error instanceof ServerError) {
volleyerror = "ServerError";

} else if (error instanceof AuthFailureError) {
volleyerror = error.getMessage();

} else if (error instanceof ParseError) {
volleyerror = "ParseError";
} else if (error instanceof NoConnectionError) {
volleyerror = "NoConnectionError";
} else if (error instanceof TimeoutError) {
volleyerror = "TimeoutError";
}
//Toast.makeText(getApplicationContext(), volleyerror, Toast.LENGTH_LONG).show();

}
})
{
@override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
//headers.put("Content-Type", "application/json; charset=UTF-8");
headers.put("Content-Type", "application/x-www-form-urlencoded");
//headers.put("Content-Type","application/text/html; charset=us-ascii");
//headers.put("Content-Type","text/plain; charset=utf-8");
headers.put("Authorization","Bearer "+ LoginRedirectActivity.authToken);
return headers;
}
};



queue.add(imgrequest);
 
Last edited:

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones