我正在使用 volley 从具有意图服务的服务器获取响应,但无法从服务器获取响应。Intent 服务每次都在调用,但没有从服务器获得响应。这是我的凌空代码意图服务:-
public class SampleSchedulingService extends IntentService {
String BASE_URL = "http://192.168.1.125:8080/";
String REG_CHECK = BASE_URL + "" + "services/account/check";
/**
* @param name
*/
public SampleSchedulingService() {
super("MYSCHEDULINGSERVICE");
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see android.app.IntentService#onHandleIntent(android.content.Intent)
*/
@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
//Log.d(getClass().getSimpleName(), "I ran!");
updateLatLong();
//SampleAlarmReceiver.completeWakefulIntent(intent);
}
/**
*
*/
private void updateLatLong() {
// TODO Auto-generated method stub
HashMap<String, String> params = new HashMap<String, String>();
params.put("imeiNo", "myImeiNumber");
Log.d(getClass().getSimpleName(), params.toString());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
VolleyHelper.POST, REG_CHECK,
new JSONObject(params), onJsonObjectReqResponse(), null);
ApplicationController.getInstance()
.addToRequestQueue(jsonObjectRequest);
}
/**
* @return
*/
private Response.Listener<JSONObject> onJsonObjectReqResponse() {
// TODO Auto-generated method stub
return new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// TODO Auto-generated method stub
try {
Log.d(getClass().getSimpleName(), response.toString());
} catch (Exception e) {
// TODO: handle exception
}
}
};
}
}