I am creating an android app with the Google Volley Api that handles the connection between my app and my php script. For some reason, the app does not send any data to my server, maybe some one here can figure it out?
My getParams()
method is called correctly, but when I try to print it, it returns null! Everything is actually working, except for that data is not passed correctly I believe, since my php script complains about variables that are null
public class Server_interaction
{
String server_url = "http://xxxxxx/update_location.php"; //hidden from you ;)
String response_string;
RequestQueue queue;
Context context;
public Server_interaction(Context context)
{
this.context = context;
queue = Server_singleton.getInstance(context).getRequestQueue();
}
public static final String TAG = Server_interaction.class.getSimpleName();
public void post_request(final VolleyCallback callback)
{
StringRequest stringRequest = new StringRequest(Request.Method.POST, server_url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
response_string = response;
callback.onSuccess(response_string);
//requestQueue.stop();
Log.i(TAG, "the response is: "+ response_string);
}
}
, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error){
response_string = "Something went wrong";
//error.printstacktrace()
//requestQueue.stop();
Log.i(TAG, "something went wrong. Is the server up and running?");
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
String the_name = "olaf";
String the_mail = "lalalal";
String the_country = "Norway";
String the_latitude = "33";
String the_longitude = "99";
Map<String, String> params = new HashMap<String, String>();
params.put("name", the_name);
params.put("email", the_mail);
params.put("country", the_country);
params.put("latitude", String.valueOf(the_latitude));
params.put("longitude", String.valueOf(the_longitude));
Log.i(TAG, "inside getparams : "+ super.getParams());
return super.getParams();
}
};//stringrequest parameter end
//add request to requestqueue
Server_singleton.getInstance(context).addToRequestQueue(stringRequest);
Log.i(TAG, "the response again:: "+ response_string);
}
}