I am developing an application that sends a lot of data to the server. Now I want to send an array of params to a php page using volley.But, I can not send it.
Code for adding parameters as an Array.
String[] arr =new String[7]; for(int i=1;i<=7;i++) { arr[i]="questionId_"+i+"_"+"ans_"+i; } HashMap<String ,String[]> params=new HashMap<String, String[]>(7); params.put("params", arr);
Code for server request
RequestQueue que=Volley.newRequestQueue(this); final ProgressDialog dialog = new ProgressDialog(HealthMyHistory.this); dialog.setTitle("Please Wait"); dialog.setMessage("Sending Data"); dialog.setCancelable(false); dialog.show(); CustomJobjectRequest jsObjRequest = new CustomJobjectRequest(Method.POST, url, params, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { dialog.dismiss(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError response) { dialog.dismiss(); Toast.makeText(getApplicationContext(), "Unable to Send Data!"+" "+response.toString(), Toast.LENGTH_SHORT).show(); } }); que.add(jsObjRequest); } Problem is in CustomJobjectRequest there is no constructor available of type in which Hashmap accepts string & array as argument.How to do it ?
Code or CustomJsonObjectRequest
package com.example.healthcoach.data; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; import com.android.volley.NetworkResponse; import com.android.volley.ParseError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.Response.ErrorListener; import com.android.volley.Response.Listener; import com.android.volley.toolbox.HttpHeaderParser; public class CustomJobjectRequest extends Request<JSONObject>{ private Listener<JSONObject> listener; private Map<String, String> params; public CustomJobjectRequest(String url, Map<String, String> params, Listener<JSONObject> reponseListener, ErrorListener errorListener) { super(Method.POST, url, errorListener); this.listener = reponseListener; this.params = params; } public CustomJobjectRequest(int method, String url, Map<String, String> params, Listener<JSONObject> reponseListener, ErrorListener errorListener) { super(method, url, errorListener); this.listener = reponseListener; this.params = params; } public CustomJobjectRequest(int post, String url, HashMap<String, String[]> params2, Listener<JSONObject> listener2, ErrorListener errorListener) {