Android Volley Library不会返回整个响应数据

时间:2022-10-22 20:32:44

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.

Volley库不会返回整个响应数据。它只返回响应数据的一部分。我叫drupal服务。下面是我的代码。

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 个解决方案

#1


2  

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)

这不是Volley的问题!,这是logcat显示有限大小数据的问题(限制)。 (我假设你正在从你的代码中读取logcat中的响应)

if you are using eclipse here is the solution

如果你在这里使用eclipse是解决方案

 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

注意:$ adb logcat -g环形缓冲区为64Kb(消耗63Kb),最大条目为4096b,最大有效载荷为4076b

LogCat is very much device dependent. The size and also the handling of bad character differs between different handsets.

LogCat非常依赖于设备。不同手机的大小和不良角色的处理也不同。

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]

#1


2  

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)

这不是Volley的问题!,这是logcat显示有限大小数据的问题(限制)。 (我假设你正在从你的代码中读取logcat中的响应)

if you are using eclipse here is the solution

如果你在这里使用eclipse是解决方案

 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

注意:$ adb logcat -g环形缓冲区为64Kb(消耗63Kb),最大条目为4096b,最大有效载荷为4076b

LogCat is very much device dependent. The size and also the handling of bad character differs between different handsets.

LogCat非常依赖于设备。不同手机的大小和不良角色的处理也不同。

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]