private void sendRateToAPI(RatingBar r1, RatingBar r2, RatingBar r3, RatingBar r4) {
    params.put("rating1", String.valueOf(r1.getRating()));
    params.put("rating2", String.valueOf(r2.getRating()));
    params.put("rating3", String.valueOf(r3.getRating()));
    params.put("rating4", String.valueOf(r4.getRating()));
    params.put("trainingID", aid);
    params.put("device", "android");
    params.put("mobileNumber", ApplicationLoader.getPreferences().getMobileNumber());

    // post request to server

    Log.d("device", params.get("device").toString());
    ConnectionDetector cd = new ConnectionDetector(TrainingVideo.this);
    Boolean isInternetPresent = cd.isConnectingToInternet(); //
    if (isInternetPresent && params.get("device").equalsIgnoreCase("android")) {
      SendRating checkLoginTask = new SendRating(params, TrainingVideo.this);
      checkLoginTask.execute(com.mobcast.util.Constants.TRAIN_RATE);
    }
  }
    @Override
    protected String doInBackground(String... params1) {

      try {

        if (this.isCancelled()) {
          Log.e("background task", "canceled");

        } else {

          JSONArray jsonArray = new JSONArray(response);
          Log.d("Number of entries", jsonArray.length() + "");
          JSONObject jObject1 = jsonArray.getJSONObject(jsonArray.length() - 1);
          id = jObject1.getString("ID");

          SharedPreferences pref;
          pref = getSharedPreferences("MobCastPref", 0);
          pref.edit().putString("lastTraining", id).commit();
          ApplicationLoader.getPreferences().setLastTrainingId(id); // ADDED VIKALP PULL SERVICE
          for (int i = 0; i < jsonArray.length(); i++) {
            if (this.isCancelled()) {
              Log.e("background task", "canceled");
              break;

            } else {

              // do your work here

              JSONObject jObject = jsonArray.getJSONObject(i);

              id = jObject.getString("ID");
              title = jObject.getString("title");
              //							SU VIKALP DATE ORDER ISSUE
              //							detail = jObject.getString("detail");
              detail = Utilities.convertdate(jObject.getString("detail"));
              //							EU VIKALP DATE ORDER ISSUE
              ss = jObject.getString("ss");
              name = jObject.getString("name");
              type = jObject.getString("type");
              summary = jObject.getString("summary");
              link = jObject.getString("link");

              String readStatus = jObject.getString("readStatus");
              try {
                contentExpiry = Utilities.convertdate(jObject.getString("expiry")); // ADDED VIKALP
                // CONTENT
                // EXPIRY
              } catch (Exception e) {
                Log.i(TAG, e.toString());
              }

              title = title.replaceAll("\\\\", "");
              summary = summary.replaceAll("\\\\", "");
              link = link.replaceAll(" ", "%20");

              Log.v("Training ", "in downloadforTraining");
              String ename = System.currentTimeMillis() + "";

              if (false) {
                try {
                  URL url = new URL(link);
                  String root = Environment.getExternalStorageDirectory().toString();
                  Log.v("type is ", type.toString());

                  String foldername = "";
                  if (type.contentEquals("pdf")) foldername = getString(R.string.pdf);
                  else if (type.contentEquals("ppt")) foldername = getString(R.string.ppt);
                  else if (type.contentEquals("doc")) foldername = getString(R.string.doc);
                  else if (type.contentEquals("xls")) foldername = getString(R.string.xls);
                  else if (type.contentEquals("video")) foldername = "mobcast_videos";
                  else if (type.contentEquals("audio")) foldername = "mobcast_audio";

                  File myDir = new File(root + Constants.APP_FOLDER + foldername);

                  String fname = ename;

                  myDir.mkdirs();

                  if ((type.contentEquals("audio")) || (type.contentEquals("video"))) {
                    fname = name;
                  }

                  File file = new File(myDir, fname);
                  if (file.exists()) file.delete();
                  URLConnection ucon = url.openConnection();
                  InputStream is = ucon.getInputStream();
                  BufferedInputStream bis = new BufferedInputStream(is);
                  ByteArrayBuffer baf = new ByteArrayBuffer(50);
                  int current = 0;
                  while ((current = bis.read()) != -1) {
                    baf.append((byte) current);
                  }
                  FileOutputStream fos = new FileOutputStream(file);
                  fos.write(baf.toByteArray());
                  fos.close();
                  announce.open();
                  long x =
                      announce.createTraining(
                          title, detail, name, summary, type, ename, id, ss, contentExpiry, link);
                  if (readStatus.contentEquals("true")) {
                    announce.readrow(x + "", AnnounceDBAdapter.SQLITE_TRAINING);
                  }
                  announce.close();

                } catch (Exception e) {
                  continue;
                }
              }
              announce.open();
              long x =
                  announce.createTraining(
                      title, detail, name, summary, type, ename, id, ss, contentExpiry, link);
              if (readStatus.contentEquals("true")) {
                announce.readrow(x + "", AnnounceDBAdapter.SQLITE_TRAINING);
              }
              announce.close();
            }
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      }

      Log.e("response", response);

      return null;
    } // End of doInBackgrounf