1

I want to hit an api where i will get lots of values and want to show on the listview.

Showing the data on listview i can do that but problem is the i can not load full data in my android app. when i hit the api in response only i get few data or can say only few line but the data is in thousands of line.

When i hit the api from web browser it shows all the data but when i use it on my android app on the button hit is only gives limited data.

Thanks in Advance :)

Code for my getting data on button hit

try {
                 String url = "my url";

             HttpHandler sh = new HttpHandler();

                // Making a request to url and getting response
                String jsonStr = sh.makeServiceCall(url);


                Log.e("Response from url:", "" + jsonStr);

        }

+++++++++++++++++++++++++
HttpHandler class code

public class HttpHandler {

private static final String TAG = HttpHandler.class.getSimpleName();

public HttpHandler() {
}

public String makeServiceCall(String reqUrl) {
    String response = null;
    try {
        URL url = new URL(reqUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        // read the response
        InputStream in = new BufferedInputStream(conn.getInputStream());
        response = convertStreamToString(in);
    } catch (MalformedURLException e) {
        Log.e(TAG, "MalformedURLException: " + e.getMessage());
    } catch (ProtocolException e) {
        Log.e(TAG, "ProtocolException: " + e.getMessage());
    } catch (IOException e) {
        Log.e(TAG, "IOException: " + e.getMessage());
    } catch (Exception e) {
        Log.e(TAG, "Exception: " + e.getMessage());
    }
    return response;
}

private String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line).append('\n');
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}

}

  • How do you know it's giving limited data on your device? Have you printed the length of the response? Because the debugger cuts off data when it's too long – Denny May 04 '17 at 10:53
  • put your json parsing code. – Bhupat Bheda May 04 '17 at 10:56
  • @Denny i i have log the values of response. It showed only 40-50 line data only. – Abhishek Punia May 04 '17 at 11:00
  • thanks everyone for your concern :) and @Denny thanks for the information about debugger i was printing the response directly show it was showing limited but by printing one by one i got all the values. – Abhishek Punia May 04 '17 at 11:06
  • @pskink it was showing only 40-50 lines data i didnt knew that debugger only show limited lines of data. now its working – Abhishek Punia May 04 '17 at 11:07
  • Possible duplicate of [Android - Set max length of logcat messages](http://stackoverflow.com/questions/8888654/android-set-max-length-of-logcat-messages) – Denny May 04 '17 at 11:09

1 Answers1

2

Seems like a debugger issue cutting off messages that are too long

See Android - Set max length of logcat messages for more

Community
  • 1
  • 1
Denny
  • 1,766
  • 3
  • 17
  • 37