问题
Volley library doesn't return whole response data. It only return the part of the response data. I am calling drupal services. Below is my code for it.
public void BoardRoomRequest() {
pdialog = new ProgressDialog(BoardRoom.this);
pdialog.setTitle("Please wait....");
String url = Global_Application.url + "views/boardroom";
Log.d("url========", url);
Map<String, String> params = new HashMap<String, String>();
StringRequest req = new StringRequest(Request.Method.GET,
getApplicationContext(), url, params,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// TODO Auto-generated method stub
Log.d("Response", response);
pdialog.dismiss();
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("Error.Response", error.toString());
pdialog.dismiss();
}
});
queue.add(req);
pdialog.show();
}
回答1:
It's not the problem with Volley!, it's the problem(limitation) of logcat for displaying limited size of data. (I'm assuming you are reading the response in logcat from your code)
if you are using eclipse here is the solution
public void BoardRoomRequest() {
pdialog = new ProgressDialog(BoardRoom.this);
pdialog.setTitle("Please wait....");
String url = Global_Application.url + "views/boardroom";
Log.d("url========", url);
Map<String, String> params = new HashMap<String, String>();
StringRequest req = new StringRequest(Request.Method.GET,
getApplicationContext(), url, params,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// TODO Auto-generated method stub
// Log.d("Response", response); //can't display more data
//=========================
longInfo(response); //solution for displaying more data in logcat
//=========================
pdialog.dismiss();
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("Error.Response", error.toString());
pdialog.dismiss();
}
});
queue.add(req);
pdialog.show();
}
public void longInfo(String str) {
if(str.length() > 4000) {
Log.i("",str.substring(0, 4000));
longInfo(str.substring(4000));
} else
Log.i("",str);
}
Note: $ adb logcat -g ring buffer is 64Kb (63Kb consumed), max entry is 4096b, max payload is 4076b
LogCat is very much device dependent. The size and also the handling of bad character differs between different handsets.
Give it try for this also:
import java.util.*;
class Test
{
public static void main(String[] args)
{
System.out.println(Arrays.toString(
"Thequickbrownfoxjumps".split("(?<=\\G.{4})")
));
}
}
output: [Theq, uick, brow, nfox, jump, s]
来源:https://stackoverflow.com/questions/18738855/android-volley-library-doent-return-whole-response-data