コード例 #1
0
 @Override
 protected List<JSONObject> doInBackground(Void... params) {
   List<JSONObject> checkins = new ArrayList<JSONObject>();
   try {
     ACSClient sdk = DemoApplication.getSdk();
     Map<String, Object> data = new HashMap<String, Object>();
     data.put("place_id", place.getString("id"));
     CCResponse response =
         sdk.sendRequest("checkins/search.json", CCRequestMethod.GET, data, false);
     JSONObject responseJSON = response.getResponseData();
     CCMeta meta = response.getMeta();
     if ("ok".equals(meta.getStatus())
         && meta.getCode() == 200
         && "searchCheckins".equals(meta.getMethod())) {
       JSONArray checkinsJArray = responseJSON.getJSONArray("checkins");
       for (int i = 0; i < checkinsJArray.length(); i++) {
         checkins.add(checkinsJArray.getJSONObject(i));
       }
     }
   } catch (ACSClientError e) {
     e.printStackTrace();
   } catch (JSONException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return checkins;
 }
コード例 #2
0
  protected void performCheckin() {

    JSONObject checkin = null;
    String errorMsg = null;
    try {
      ACSClient sdk = DemoApplication.getSdk();
      Map<String, Object> data = new HashMap<String, Object>();
      try {
        data.put("place_id", place.getString("id"));
      } catch (JSONException e) {
        e.printStackTrace();
      }

      CCResponse response =
          sdk.sendRequest("checkins/create.json", CCRequestMethod.POST, data, false);

      JSONObject responseJSON = response.getResponseData();
      CCMeta meta = response.getMeta();
      if ("ok".equals(meta.getStatus())
          && meta.getCode() == 200
          && "createCheckin".equals(meta.getMethod())) {
        JSONArray checkins = null;
        try {
          checkins = responseJSON.getJSONArray("checkins");
          checkin = checkins.getJSONObject(0);
          listOfCheckin.add(0, checkin);
        } catch (JSONException e) {
          e.printStackTrace();
        }
        showCheckins();
      } else {
        errorMsg = meta.getMessage();
      }

    } catch (ACSClientError e) {
      errorMsg = e.getMessage();
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (errorMsg != null) {
      AlertDialog alertDialog = new AlertDialog.Builder(this).create();
      alertDialog.setTitle("Checkin Failed");
      alertDialog.setMessage(errorMsg);
      alertDialog.setButton(
          "OK",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              // here you can add functions
              dialog.dismiss();
            }
          });
      alertDialog.setIcon(R.drawable.icon);
      alertDialog.show();
    }
  }