0

My question is how to fetch an image from server and set into imageview using Async Http Response Handler. The JsonObject for image is "profile_image" which needs to be fetched from the Rest api and display into my ImageView.

My code:

AsyncHttpClient client = new AsyncHttpClient();
        //private ProgressDialog Dialog = new ProgressDialog(post.this);
        List<String> userCredentials = UserUtils.getLoginDetails();
        client.addHeader("x-user-id", userCredentials.get(0));
        client.addHeader("x-auth-token", userCredentials.get(1));
        client.get("https://", new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {

                final String response = new String(responseBody);
                android.util.Log.e("Response", "" + response);

                try {
                    JSONObject jsonObject = new JSONObject(response);
                    JSONObject object = jsonObject.getJSONObject("user");
                    String attr1 = object.getString("name");
                    data = "" + attr1;
                    textView15.setText(data);

                    if (object.has("profession")) {
                        String attr2 = object.getString("profession");
                        data2 = "" + attr2;
                        textView16.setText(data2);
                    }
                    if(object.has("company")){
                        String attr3 = object.getString("company");
                        data3 = "" + attr3;
                     textView38.setText(data3);
                    }

                    if(object.has("profile_image")){

                    }
                    JSONObject jsonObject1 = object.getJSONObject("emails");
                    JSONArray jsonArray = jsonObject1.getJSONArray("address");
                    for (int i = 0; i < jsonArray.length(); i++) {
                        data += "\n"
                                + jsonArray.getJSONObject(i).getString("address")
                                .toString();




                       // data += " Name= "+ attr1 +"  \n ";
                    }
                    textView15.setText(data);
                    //Dialog.dismiss();
                } catch (JSONException e) {e.printStackTrace();}
            }

API code:

 "user": {

                                                                      "profile_image": "https:////image/upload/v1455884587/endflvkyqv3ot37g4unc.png",
                                                                   "profile_public_id": "endflvkyqv3ot37g4unc"
                                                                    }
                                                                  }
1
  • Can you post your sample JSON? What problem are you facing while setting it? Is there an error? Commented Feb 21, 2016 at 5:29

1 Answer 1

0

Use Picasso to load Image From SERVER / URL :

but, First check Your ImageResponse

and before using Picasso don't forgtt to Add Picasso library, For Library and More about Picasso see here

if(object.has("profile_image")){
Picasso.with(this)
          .load("" + object.getString("profile_image"))
          .fit()
          .into(imageView);
}
Sign up to request clarification or add additional context in comments.

3 Comments

not support?? make sure that you are using latest Async http client if not then change it.
ya I am using latest.
hope, you have already added Library file for Picasso before use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.