/** 将设备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(); } }
@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; }
public void cancelTask(boolean cancel) { super.cancel(cancel); // 由于IO操作是不可中断的,所以我们这里关闭IO流来终止任务 NetworkUtils.closeInputStream(_is); }