private void uploadRecord(String id) { String[] key = {"cmd", "userno", "fileno", "togetherid"}; String[] value = {"uploadappointinstallsound", userNo, orderId, id}; MultipartBuilder builder = new MultipartBuilder().type(MultipartBuilder.FORM); for (int i = 0; i < key.length; i++) { builder.addFormDataPart(key[i], value[i]); } String fileName = recordFile.getName(); RequestBody fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), recordFile); builder.addFormDataPart("", fileName, fileBody); HttpUtils.sendHttpPostRequest( builder.build(), new HttpCallbackListener() { @Override public void onFinish(final String response) { Log.e("responseVoice", response); handler.post( new Runnable() { @Override public void run() { if (response.substring(0, 1).equals("E")) { ToastUtil.showToast(DistributeActivity.this, "上传录音失败", Toast.LENGTH_SHORT); pDialog.dismiss(); } else { recordFile.delete(); recordFile = null; saveInfo(response); } } }); } @Override public void onError(Exception e) { handler.post( new Runnable() { @Override public void run() { ToastUtil.showToast(DistributeActivity.this, "与服务器断开连接", Toast.LENGTH_SHORT); pDialog.dismiss(); } }); } }); }
private void query() { String orderId = et_orderId.getText().toString().trim(); String url = null; try { url = "?cmd=getfinishconstruction&userno=" + URLEncoder.encode(userNo, "UTF-8") + "&fileno=" + URLEncoder.encode(orderId, "UTF-8") + "&enddate=&isfinish=1"; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } HttpUtils.sendHttpGetRequest( url, new HttpCallbackListener() { @Override public void onFinish(final String response) { Log.e("response", response); handler.post( new Runnable() { @Override public void run() { ArrayList<Acceptance> list = JsonParseUtils.getAcceptanceInfo(response); accList.clear(); accList.addAll(list); adapter.notifyDataSetChanged(); } }); } @Override public void onError(Exception e) { handler.post( new Runnable() { @Override public void run() { ToastUtil.showToast(getActivity(), "与服务器断开连接", Toast.LENGTH_SHORT); } }); } }); }
private void distribute() { pDialog = new ProgressDialog(this); pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); pDialog.setMessage("正在提交数据..."); pDialog.show(); StringBuilder sb = new StringBuilder(); for (Subordinate sub : subordinates) { if (sub.isCheck()) { sb.append(sub.getUserNo() + ","); } } String executors = sb.toString().substring(0, sb.toString().length() - 1); Log.e("executors", executors); JSONArray jsonArray = new JSONArray(); for (int i = 0; i < picUrls.size() - 1; i++) { try { JSONObject jsonObject = new JSONObject(); jsonObject.put("PicUri", picUrls.get(i).getPicUrl()); jsonArray.put(jsonObject); } catch (JSONException e) { e.printStackTrace(); } } Log.e("json", jsonArray.toString()); String jsonData = ""; if (!jsonArray.toString().equals("[]")) { jsonData = jsonArray.toString(); } final RequestBody requestBody = new FormEncodingBuilder() .add("cmd", "doappoint") .add("userno", userNo) .add("fileno", orderId) .add("installuserno", executors) .add("installcontent", et_remarks.getText().toString().trim()) .add("estimatefinishdate", tv_deadline.getText().toString()) .add("picuri", jsonData) .build(); HttpUtils.sendHttpPostRequest( requestBody, new HttpCallbackListener() { @Override public void onFinish(final String response) { Log.e("response", response); handler.post( new Runnable() { @Override public void run() { if (response.substring(0, 1).equals("E")) { ToastUtil.showToast(DistributeActivity.this, "派工失败", Toast.LENGTH_SHORT); pDialog.dismiss(); } else { if (recordFile == null) { saveInfo(response); } else { uploadRecord(response); } } } }); } @Override public void onError(Exception e) { handler.post( new Runnable() { @Override public void run() { ToastUtil.showToast(DistributeActivity.this, "与服务器断开连接", Toast.LENGTH_SHORT); pDialog.dismiss(); } }); } }); }