我开发了一个Android应用程序,它将传感器数据发送到灯服务器,用于在后台使用服务发送数据,对于支持我已经使用过PHP。当我运行应用程序时后台服务启动我从服务器获取数据成功插入消息灯服务器行正在更新但值不存储。 null值存储请帮我找出代码中的问题?
public void data() throws JSONException {
final String LIGHTSENS, LIGHTDATA, TEMPSENSOR, TEMPDATA, AMBTEMPSENSOR, AMBTEMDATA, PRESSURESENS, PRESSUREDATA, LATTITUDE, LONGITUDE, DATE, TIME;
LIGHTSENS = String.valueOf(lr1);
LIGHTDATA = String.valueOf(ld1);
TEMPSENSOR = String.valueOf(tr1);
TEMPDATA = String.valueOf(td1);
AMBTEMPSENSOR = String.valueOf(atr1);
AMBTEMDATA = String.valueOf(atd1);
PRESSURESENS = String.valueOf(pr1);
PRESSUREDATA = String.valueOf(pd1);
LATTITUDE = String.valueOf(la);
LONGITUDE = String.valueOf(lg);
StringRequest stringRequest = new StringRequest(Request.Method.POST, Server_url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
Toast.makeText(sens.this, response.toString(), Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(sens.this, error.toString(), Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError, AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
params.put("LIGHTSENS", LIGHTSENS);
params.put("LIGHTDATA", LIGHTDATA);
params.put("TEMPSENSOR", TEMPSENSOR);
params.put("TEMPDATA", TEMPDATA);
params.put("AMBTEMPSENSOR", AMBTEMPSENSOR);
params.put("AMBTEMDATA", AMBTEMDATA);
params.put("PRESSURESENS", PRESSURESENS);
params.put("PRESSUREDATA", PRESSUREDATA);
params.put("LATTITUDE", LATTITUDE);
params.put("LONGITUDE", LONGITUDE);
return super.getParams();
//params.put("Content-Type", "application/json; charset=utf-8");
//params.put("User-agent", System.getProperty("http.agent"));
//return params;
}
};
//Mysingleton.getmInstance(sens.this).addTorequestque(stringRequest);
// RequestQueue rq = Volley.newRequestQueue(this);
RequestQueue requestQueue= Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
// RequestQueue requestQueue = Volley.newRequestQueue(this);
//requestQueue.add(stringRequest);
}
答案 0 :(得分:0)
试试这个,
InverseBindingAdapter