Как отправить несколько запросов данных из списка с помощью jsonobjectrequest в Android - PullRequest
0 голосов
/ 01 октября 2019

Я хочу отправить данные из списка с помощью jsonobjectrequest в volley.and получить несколько ответов, если их больше, чем list. Предположим, если список 2 и получить ответ 2 (100001,100002)

мои данные отправляются несколько раз, но ответ только один.

Я хочу получить несколько ответов, если отправка нескольких запросов ... только дляиспользуя jsonobjectrequest без массива json. Пожалуйста, предложите мне.

final ProgressDialog dialog = new ProgressDialog(AttendanceFloatingButtonActivity.this, R.style.MyAlertDialogStyle);
    dialog.setTitle("Data is Uploading");
    dialog.setMessage("please wait...Press the back button after the process is complete.!");

    if (dialog != null) {

        dialog.show();
    }


    JsonObjectRequest jsonObjectRequest = null;


    for (int i = 0; i < listdatafetch.size(); i++) {

        final List<DataModelAttendance> imageList = db.getBase64(Integer.valueOf(listdatafetch.get(i).getIdattend()));

        for (int j = 0; j < imageList.size(); j++) {

            if (listdatafetch.get(i).getOutdateatt() != null && imageList.get(j).getOutimage64() != null) {

                Log.e("Table", "Attendance");
                Log.e("ID", "0");
                Log.e("InDate", listdatafetch.get(i).getAttdate());
                Log.e("InAtt", listdatafetch.get(i).getAttnamevalue());
                Log.e("InRemarks", listdatafetch.get(i).getAttremarks());
                Log.e("InImage", imageList.get(j).getImages64());
                Log.e("InLocation", db.InLocationatt() + ";" + db.inaddressatt());
                Log.e("OutDate", listdatafetch.get(i).getOutdateatt());
                Log.e("AttType", listdatafetch.get(i).getOutatttypevalue());
                Log.e("EmployeeID", listdatafetch.get(i).getOutempnamevalue());
                Log.e("OutRemarks", listdatafetch.get(i).getOutremarks());
                Log.e("OutImage", imageList.get(j).getOutimage64());
                Log.e("CUID", db.erpUserId());
                Log.e("OutLocation", location + ";" + addressout);

                try {
                    final String base64att = imageList.get(j).getImages64();
                    final JSONObject jsonObject = new JSONObject();
                    jsonObject.put("Table", "Attendance");
                    jsonObject.put("ID", Integer.parseInt("0"));
                    jsonObject.put("InDate", listdatafetch.get(i).getAttdate());
                    jsonObject.put("AttType", listdatafetch.get(i).getAttnamevalue());
                    jsonObject.put("InRemarks", listdatafetch.get(i).getAttremarks());
                    jsonObject.put("InImage", imageList.get(j).getImages64());
                    jsonObject.put("InLocation", db.InLocationatt() + ";" + db.inaddressatt());
                    jsonObject.put("OutDate", listdatafetch.get(i).getOutdateatt());
                    jsonObject.put("AttType", listdatafetch.get(i).getOutatttypevalue());
                    jsonObject.put("EmployeeID", listdatafetch.get(i).getOutempnamevalue());
                    jsonObject.put("OutRemarks", listdatafetch.get(i).getOutremarks());
                    jsonObject.put("OutImage", imageList.get(j).getOutimage64());
                    jsonObject.put("CUID", db.erpUserId());
                    jsonObject.put("OutLocation", location + ";" + addressout);





                    final JSONObject jsonObject1 = new JSONObject();
                    jsonObject1.put("data", jsonObject);
                    jsonObjectRequest = new JsonObjectRequest
                            (Request.Method.POST, webservicepost, jsonObject1, new Response.Listener<JSONObject>() {
                                @Override
                                public void onResponse(JSONObject response) {

                                    dialog.dismiss();
                                    Log.e("response", String.valueOf(response));


                                    try {

                                        String get = response.getString("success");
                                        if (response.getString("success").equals("0")) {
                                            Toast.makeText(AttendanceFloatingButtonActivity.this, "Wrong Creadentials", Toast.LENGTH_SHORT).show();
                                        } else if (response.getString("success").equals("1")) {
                                            Toast.makeText(AttendanceFloatingButtonActivity.this, "Data Saved...Please wait", Toast.LENGTH_SHORT).show();
                                            Log.e("Response", String.valueOf(response));
                                            String idattflot = response.getString("ID");
                                            getcameraphoto(base64att, idattflot);

                                        }

                                    } catch (Exception e) {
                                        Log.e("error  in save", e.getMessage());
                                        Toast.makeText(AttendanceFloatingButtonActivity.this, "response  error" + e.getMessage(), Toast.LENGTH_SHORT).show();

                                    }


                                }
                            }, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {


                                    if (dialog != null) {

                                        Toast.makeText(AttendanceFloatingButtonActivity.this, " error" + error.getMessage(), Toast.LENGTH_SHORT).show();
                                        dialog.dismiss();

                                    }

                                }
                            });

                } catch (JSONException e) {

                    dialog.dismiss();
                    Toast.makeText(AttendanceFloatingButtonActivity.this, " JSONException" + e.getMessage(), Toast.LENGTH_SHORT).show();
                }

            } else {


            }
        }


    }

    synchdatadel();

    RequestQueue queue = Volley.newRequestQueue(AttendanceFloatingButtonActivity.this);
    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(20000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    queue.add(jsonObjectRequest);
...