Пример #1
0
    @Override
    protected JSONObject doInBackground(Object... params) {
      Address requestAddress = (Address) params[1];

      ClientResource res = new ClientResource(params[0].toString());
      res.setMethod(Method.POST);

      double latitude = 0;
      double longitude = 0;

      // Location returns null if no position is currently available. In this case, cancel the
      // request.
      if (requestAddress == null) {

        JSONObject o = new JSONObject();
        try {
          o.put("ID", -1);
        } catch (JSONException e) {
          e.printStackTrace();
        }
        return o;
      } else {
        latitude = requestAddress.getLatitude();
        longitude = requestAddress.getLongitude();
      }

      int bottomId = 10000; // Indicates that we want the latest.

      int sort = ((Integer) params[2]).intValue();

      JSONObject obj =
          JSONMessage.getPosts(
              bottomId, "", Double.valueOf(latitude), Double.valueOf(longitude), sort);
      StringRepresentation stringRep = new StringRepresentation(obj.toString());

      stringRep.setMediaType(MediaType.APPLICATION_JSON);
      JSONObject o = null;
      try {
        Representation r = res.post(stringRep);
        o = new JSONObject(r.getText());
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      return o;
    }