我有一个片段,要求Volley请求并获取json:
RequestQueue requestQueue = new Volley.newRequestQueue(getContext());
StringRequest jsonArrayRequest = new StringRequest(Request.Method.POST, "..here is url..",
new Response.Listener<String>() {
@Override
public void onResponse(String fakeresponse) {
System.out.println("json fetched successfully");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("failed to fetch json");
}
}){
@Override
protected Map<String, String> getParams() {
Map<String, String> map = new HashMap<String, String>();
return map;
}
};
requestQueue.add(jsonArrayRequest);
当我在Pixel 2的模拟器中运行此代码时,代码正在工作,并且在logcat中获得“成功提取json”。但是,当我在Nexus 4中运行应用程序时,没有任何反应。请求未实现,我什至没有onErrorResponse
,但什么都没得到,但这在Logcat中是这样的:
D/: HostConnection::get() New Host Connection established 0xe8b9ee80, tid 8718
I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xebd05360: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xebd05360: ver 3 0 (tinfo 0xebd03280)
D/EGL_emulation: eglMakeCurrent: 0xebd05360: ver 3 0 (tinfo 0xebd03280)