Пример #1
0
  /*
   * 单独上传amr格式语音文件 Common/phonetic 参数 speech 文件 oauth_token 不能为空
   */
  public void phonetic(RequestParams params, final OnAsynInsertListener listener) {

    if (NetUtil.isNetworkAvailable()) {
      HttpUtil.post(
          "api/common/phonetic",
          true,
          params,
          new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
              if (arg0 != 200) {
                listener.OnAsynRequestFail(
                    "-1", GezitechApplication.getContext().getString(R.string.data_error));
              }
              try {
                Response response = new Response(new String(arg2));
                JSONObject root = response.asJSONObject();
                if (root.getInt("state") != 1) { // 0
                  if (listener != null) listener.OnAsynRequestFail("-1", root.getString("msg"));
                  return;
                }
                JSONObject data = root.getJSONObject("data");
                String speech = data.has("speech") ? data.getString("speech") : "";
                if (speech.equals("")) {
                  listener.OnAsynRequestFail("-1", "上传失败");
                  return;
                }
                listener.onInsertDone(speech);

              } catch (Exception ex) {
                listener.OnAsynRequestFail(
                    "-1", GezitechApplication.getContext().getString(R.string.data_error));
              }
            }

            @Override
            public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
              listener.OnAsynRequestFail(
                  "-1", GezitechApplication.getContext().getString(R.string.data_error));
            }

            @Override
            public void onFinish() { // 完成后调用,失败,成功,都要掉
            }
          });
    } else {
      if (listener != null) {
        listener.OnAsynRequestFail(
            "-1", GezitechApplication.getContext().getString(R.string.network_error));
      }
    }
  }
Пример #2
0
  /**
   * 获取系统消息的更新
   *
   * <p>api/News/getNewsUpdate ctime 历史查看时间, 不传为当前时间 oauth_token oauth_token 返回数据 state 成功状态 1成功 0失败
   * msg 状态描述信息 data 有几条信息 整型
   *
   * <p>TODO()
   */
  public void getNewsUpdate(long ctime, final OnAsynInsertListener listener) {
    RequestParams params = new RequestParams();
    // params.put("ctime", ctime );
    if (NetUtil.isNetworkAvailable()) {
      HttpUtil.post(
          "api/News/getNewsUpdate/ctime/" + ctime,
          true,
          params,
          new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
              if (arg0 != 200) {
                listener.OnAsynRequestFail(
                    "-1", GezitechApplication.getContext().getString(R.string.data_error));
              }
              try {
                Response response = new Response(new String(arg2));
                JSONObject root = response.asJSONObject();
                if (root.getInt("state") != 1) { // 0
                  if (listener != null) listener.OnAsynRequestFail("-1", root.getString("msg"));
                  return;
                }

                int data = root.has("data") ? root.getInt("data") : 0;

                Log.v("测试返回", data + "========data====");
                listener.onInsertDone(data + "");

              } catch (Exception ex) {
                listener.OnAsynRequestFail(
                    "-1", GezitechApplication.getContext().getString(R.string.data_error));
              }
            }

            @Override
            public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
              listener.OnAsynRequestFail(
                  "-1", GezitechApplication.getContext().getString(R.string.data_error));
            }

            @Override
            public void onFinish() { // 完成后调用,失败,成功,都要掉
            }
          });
    } else {
      if (listener != null) {
        listener.OnAsynRequestFail(
            "-1", GezitechApplication.getContext().getString(R.string.network_error));
      }
    }
  }