示例#1
0
  // -------------- get short --------------------//
  public void getShort() {
    HttpClientHelper httpClientHelper =
        new HttpClientHelper(
            new MyJsonHttpResponseHandler() {

              @Override
              public void onFailure(Throwable error) {
                countCall = countCall + 1;
                btnRefresh.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.GONE);
              }

              @Override
              public void onSuccess(JSONArray re) {
                // insert
                for (int i = 0; i < re.length(); i++) {
                  try {
                    JSONObject jo = re.getJSONObject(i);
                    Log.i("DATA", "NEWS: " + jo.toString());
                    JSONObject news = jo.getJSONObject("news");

                    ObjPost objPost = new ObjPost();

                    int id = news.getInt("id");
                    String type = jo.getString("type");
                    String urlImage = news.getString("image");
                    String urlPost = news.getString("url");
                    String author = news.getString("author");
                    int dateUnix = news.getInt("date_unix");
                    String dateDay = news.getString("date_day");
                    String dateHour = news.getString("date_hour");
                    String title = news.getString("title");
                    String content = news.getString("content");
                    String video = "";

                    objPost.setId(id);
                    objPost.setType(type);
                    objPost.setUrlImage(urlImage);
                    objPost.setUrlPost(urlPost);
                    objPost.setAuthor(author);
                    objPost.setDateUnix(dateUnix);
                    objPost.setDateDay(dateDay);
                    objPost.setDateHour(dateHour);
                    objPost.setTitle(title);
                    objPost.setContent(content);
                    objPost.setUrlVideo(video);

                    db.insertNew(objPost);

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

                countCall = countCall + 1;
              }
            });

    httpClientHelper.getShortPost();
  }
示例#2
0
  void sendDeviceId() {
    HttpClientHelper httpClientHelper =
        new HttpClientHelper(
            new MyJsonHttpResponseHandler() {

              @Override
              public void onFailure(Throwable error) {
                Log.i("DATA", "Cap nhat device that bai");
              }

              @Override
              public void onSuccess(JSONObject re) {
                Log.i("DATA", "Cap nhat device thanh cong");
              }
            });

    httpClientHelper.registerGCM(preferenceHelper.getRegId(), "User ", "*****@*****.**");
  }