コード例 #1
0
 /**
  * 该操作是一个阻塞联网操作,不能放在UI线程 Http://www.mingdown.com/cell/ adddownloadrecord.aspx?MM=下载的名片名号
  * &&cell=下载人的默认本机号码
  *
  * @param downloadedMm 下载的名片名号
  * @param tel 下载人的默认本机号码
  * @return
  */
 public static boolean recordDownloadLocked(String downloadedMm, String tel) {
   DebugUtils.logD(TAG, "recordDownloadLocked downloadedMm=" + downloadedMm + " tel=" + tel);
   if (TextUtils.isEmpty(tel)) {
     DebugUtils.logD(TAG, "tel is empty, so we just return true");
     return true;
   }
   StringBuilder sb = new StringBuilder(mDownloadRecordUriPrefix);
   sb.append("MM=").append(downloadedMm).append("&&cell=").append(tel);
   InputStream is = null;
   try {
     is =
         NetworkUtils.openContectionLocked(
             sb.toString(), MyApplication.getInstance().getSecurityKeyValuesObject());
     DebugUtils.logD(TAG, "record download successfully.");
     return true;
   } catch (ClientProtocolException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     if (is != null) {
       try {
         is.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
   return false;
 }
コード例 #2
0
  /** 将设备Token提交服务器 */
  public void postDeviceTokenToServiceLocked() {
    DebugUtils.logD(TAG, "postDeviceTokenToServiceLocked()");
    try {
      if (MyAccountManager.getInstance().hasLoginned()
          && !TextUtils.isEmpty(getDeviceTotke())
          && !getDeviceTotkeStatus()) {
        InputStream is =
            NetworkUtils.openContectionLocked(
                HaierServiceObject.getUpdateDeviceTokenUrl(
                    String.valueOf(MyAccountManager.getInstance().getAccountObject().mAccountUid),
                    getDeviceTotke(),
                    "android"),
                MyApplication.getInstance().getSecurityKeyValuesObject());
        if (is != null) {
          HaierResultObject result = HaierResultObject.parse(NetworkUtils.getContentFromInput(is));
          NetworkUtils.closeInputStream(is);

          saveDeviceTokenStatus(result.isOpSuccessfully());
          DebugUtils.logD(TAG, result.toString());
        }
      }
    } catch (ClientProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
    @Override
    protected HaierResultObject doInBackground(Void... params) {
      HaierResultObject resultObject = new HaierResultObject();
      mAccountObject = new AccountObject();
      ;
      try {
        MyApplication.getInstance()
            .postAsync(
                new Runnable() {

                  @Override
                  public void run() {
                    mStatusView.setText(R.string.msg_login_download_accountinfo_wait);
                  }
                });
        _is =
            NetworkUtils.openContectionLocked(
                HaierServiceObject.getLoginOrUpdateUrl(mTel, mPwd), null);
        resultObject = HaierResultObject.parse(NetworkUtils.getContentFromInput(_is));
        if (resultObject.isOpSuccessfully()) {
          // 登录成功,我们解析登录返回数据
          AccountParser.parseAccountData(resultObject.mJsonData, mAccountObject);
          if (mAccountObject != null && mAccountObject.hasUid()) {
            boolean saveAccountOk =
                MyAccountManager.getInstance()
                    .saveAccountObject(
                        LoginOrUpdateAccountDialog.this.getContentResolver(), mAccountObject);
            if (!saveAccountOk) {
              // 登录成功了,但本地数据保存失败,通常不会走到这里
              resultObject.mStatusMessage =
                  LoginOrUpdateAccountDialog.this.getString(R.string.msg_login_save_success);
            }
          }
        }

      } catch (ClientProtocolException e) {
        e.printStackTrace();
        resultObject.mStatusMessage = e.getMessage();
      } catch (IOException e) {
        e.printStackTrace();
        resultObject.mStatusMessage = MyApplication.getInstance().getGernalNetworkError();
      } catch (JSONException e) {
        e.printStackTrace();
        resultObject.mStatusMessage = e.getMessage();
      } finally {
        NetworkUtils.closeInputStream(_is);
      }
      return resultObject;
    }
コード例 #4
0
 /**
  * 记录交换
  *
  * @param downloadedMm 要下载的名号
  * @param exchangeMm 用于交换的名号
  * @return 如果记录成功,返回true,否则返回false
  */
 public static boolean recordExchange(String downloadedMm, String exchangeMm) {
   StringBuilder sb = new StringBuilder("http://www.mingdown.com/cell/jiaohuan.ashx?");
   sb.append("mm1=").append(downloadedMm).append("&mm2=").append(exchangeMm);
   try {
     InputStream is =
         NetworkUtils.openContectionLocked(
             sb.toString(), MyApplication.getInstance().getSecurityKeyValuesObject());
     if (is == null) {
       return false;
     }
     String resultStr = NetworkUtils.getContentFromInput(is);
     DebugUtils.logD(TAG, "service return " + resultStr);
     if ("ok".equals(resultStr)) {
       DebugUtils.logD(TAG, "finish recording exchange " + resultStr);
       return true;
     }
   } catch (ClientProtocolException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return false;
 }