public void postLike() { RequestParams params = new RequestParams(); params.add("recipe", recipeBean.get_id()); params.add("like", String.valueOf(isLike)); String username = sp.getString(SharedPreferencesUtil.TAG_USER_NAME, ""); String password = sp.getString(SharedPreferencesUtil.TAG_PASSWORD, ""); KitchenRestClient.postWithLogin( "like", params, username, password, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { Log.e("post like", response.toString()); if (statusCode == 201) { try { likeBean = JsonTobean.getBean(LikeBean.class, response.toString()); } catch (Exception e) { e.printStackTrace(); } } } @Override public void onFailure( int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { // Toast.makeText(getApplicationContext(), "like it is wrong. Please try it.", // Toast.LENGTH_SHORT).show(); } }); }
@Override protected RequestParams getParams() { RequestParams params = new RequestParams(); params.add("method", "userloginVerify"); params.add("phone", this.params.phone); params.add("password", this.params.password); return params; }
// register gcm public void registerGCM(String regId, String name, String email) { RequestParams params = new RequestParams(); params.add("regId", regId); params.add("name", name); params.add("email", email); post(REG_GCM, params, asyncHttpResponseHandler); Log.i("URL", "URL: " + getUrlPostWithParams(BASE_URL, REG_GCM, params)); }
public void updateAppVersion() { RequestAttributes<ResBean> attrs = new RequestAttributes(appContext); attrs.setUrl(RequestURL.URL_DEVICE_UPDATE_APP_VERSION); attrs.setType(Const.ReqType.DEVICE_UPDATE_VERSION); attrs.setConverter(new GeneralConverter()); RequestParams params = new RequestParams(); params.add("device_id", DeviceInfo.getDeviceId(appContext)); params.add("app_name", Const.APP_NAME_REQ); params.add("app_version", Config.getApiVersion()); attrs.setParams(params); HttpRequestHelper.excutePostRequest(attrs, requestListener); }
@Override protected RequestParams getParams() { RequestParams params = new RequestParams(); if (this.params.sid != null) { params.add("sid", this.params.sid); } if (this.params.pkey != null) { params.add("pkey", this.params.pkey); } params.add("method", "InsertFeedbackhelp"); params.add("feedbackhelptitle", this.params.feedbackhelptitle); params.add("feedbackhelpcontent", this.params.feedbackhelpcontent); return params; }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: finish(); return true; case R.id.action_concern: RequestParams paramsConcern = new RequestParams(); final String snackText; // 设置flag,取消 or 关注,true or false; if (flagConcern) { paramsConcern.add("thing", "unconcern"); snackText = "取消成功"; flagConcern = false; } else { paramsConcern.add("thing", "concern"); snackText = "关注成功"; flagConcern = true; } paramsConcern.add("gid", gid); HttpUtil.post( "http://bbs.nankai.edu.cn/group/action", paramsConcern, new TextHttpResponseHandler() { @Override public void onFailure( int statusCode, Header[] headers, String responseString, Throwable throwable) { Log.d("Dfish", responseString + "操作失败F"); } @Override public void onSuccess(int statusCode, Header[] headers, String responseString) { Log.d("Dfish", responseString + "操作成功S"); Snackbar.make(toolbar, snackText, Snackbar.LENGTH_SHORT).show(); if (flagConcern) { fab.show(); } else { fab.hide(); } } }); break; } return false; }
/** * 调用PushManager.startWork后,sdk将对push server发起绑定请求,这个过程是异步的。绑定请求的结果通过onBind返回。 * 如果您需要用单播推送,需要把这里获取的channel id和user id上传到应用server中,再调用server接口用channel id和user id给单个手机或者用户推送。 * * @param context BroadcastReceiver的执行Context * @param errorCode 绑定接口返回值,0 - 成功 * @param appid 应用id。errorCode非0时为null * @param userId 应用user id。errorCode非0时为null * @param channelId 应用channel id。errorCode非0时为null * @param requestId 向服务端发起的请求id。在追查问题时有用; * @return none */ @Override public void onBind( Context context, int errorCode, String appid, String userId, String channelId, String requestId) { String responseString = "onBind errorCode=" + errorCode + " appid=" + appid + " userId=" + userId + " channelId=" + channelId + " requestId=" + requestId; Log.d(TAG, responseString); if (errorCode == 0) { // 绑定成功 上传channelId到服务器 RequestParams request = new RequestParams(); request.add("phone", PersonInfoLocal.getPhone(context)); request.add("platform", "android"); request.add("channel", String.valueOf(channelId)); BaseAsyncHttp.postReq( context, "/users/channel", request, new JSONObjectHttpResponseHandler() { @Override public void jsonSuccess(JSONObject resp) { // TODO Auto-generated method stub Log.d(TAG, "update channelId success"); } @Override public void jsonFail(JSONObject resp) { // TODO Auto-generated method stub } }); } // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑 // updateContent(context, responseString); }
public void reportDeviceInfo() { RequestAttributes<ResBean> attrs = new RequestAttributes(appContext); attrs.setUrl(RequestURL.URL_DEVICE_REPORT); attrs.setType(Const.ReqType.DEVICE_REPORT); attrs.setConverter(new GeneralConverter()); RequestParams params = new RequestParams(); params.add("app_type", "1"); params.add("app_name", Const.APP_NAME_REQ); params.add("device_id", DeviceInfo.getDeviceId(appContext)); params.add("device_version", DeviceInfo.getDeviceModel()); params.add("device_brand", DeviceInfo.getBrand()); params.add("os_version", DeviceInfo.getAndroidVersion()); params.add("app_version", Config.getApiVersion()); params.add("ext", DeviceInfo.getExtInfo(appContext)); attrs.setParams(params); HttpRequestHelper.excutePostRequest(attrs, requestListener); }
/* * Converts from the specified currency to BTC using the Blockchain.info API. */ private void convertToBTC(double currency) { RequestParams params = new RequestParams(); params.add("currency", currencyName); params.add("value", String.valueOf(currency)); HttpUtils.get( "https://blockchain.info/tobtc", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { String response = new String(responseBody, StandardCharsets.UTF_8); txtBtcInput.setText(response); } @Override public void onFailure( int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Toast.makeText( getApplicationContext(), getString(R.string.noInternet), Toast.LENGTH_LONG) .show(); } }); }
private void upLoadJson(Context context, String json) { // data RequestParams requestParams = new RequestParams(); requestParams.add("data", json); baseRequest( requestParams, NetUrl.UP_PROTECT, new BaseCallBack<BaseBean>() { @Override public void messageResponse(RequestType requestType, BaseBean bean, String message) { if (requestType == RequestType.messagetrue) { requestCurrentProgress++; if (requestCount == requestCurrentProgress) { callBack.jsonResponse( RequestType.messagetrue, requestCount, requestCurrentProgress); { TaskListBeanFuZhu beanFuZhu = BaseNet.getGson().fromJson(SpKey.getTaskList(), TaskListBeanFuZhu.class); m: if (beanFuZhu == null || beanFuZhu.list == null || beanFuZhu.list.size() <= 0) { } else { List<TaskMessageFuZhu> fuZhus = beanFuZhu.list; for (int u = 0; u < fuZhus.size(); u++) { TaskMessageFuZhu messageFuZhu = fuZhus.get(u); String taskCode = messageFuZhu.TaskCode; if (taskCode.endsWith(taskMessage.TaskCode)) { fuZhus.remove(messageFuZhu); SpUtil.putString(SpKey.getUerId(), BaseNet.getGson().toJson(beanFuZhu)); } break m; } } } SpUtilCurrentTaskInfo.clear(); TaskMyssageData.getInstance().clearJson(); SpUtil.putBoolean(taskMessage.TaskCode, false); SpUtil.putBoolean(taskMessage.TaskCode + SpKey.TASKSTATUE, false); } callBack.jsonResponse(RequestType.loading, requestCount, requestCurrentProgress); } else { callBack.jsonResponse(requestType, requestCount, requestCurrentProgress); } } }, BaseBean.class); }
@Override public void onClick(View v) { switch (v.getId()) { /** 这里是登录请求的事件 */ case R.id.login_login: // 登录按钮事件执行 if (HTTPConstant.HOST_URL == null) { SystemUtils.MToast("请设置Ip地址和端口号", LoginActivity.this); return; } userNameString = userNameEditText.getEditableText().toString(); passwordString = passwordEditText.getEditableText().toString(); if (userNameString.equals("") || passwordString.equals("")) { SystemUtils.MToast("请输入完整的账号密码", LoginActivity.this); return; } /** 这里是正式的HTTP请求了 */ RequestParams requestParams = new RequestParams(); // 设置请求参数 requestParams.add("admin.username", userNameString); requestParams.add("admin.password", passwordString); /** 通过这个BaseConnectTemplet,这是一个加载数据的公共类,他在加载的时候,会弹出一个对话框 */ BaseConnectTemplet<UserMessage> baseConnectTemplet = new BaseConnectTemplet<>( LoginActivity.this, "提示", "正在登陆", httpConnectReciver, requestParams, HTTPConstant.LOGIN_URL, new TypeToken<UserMessage>() {}.getType()); baseConnectTemplet.setProgressViewCanCancel(); baseConnectTemplet.getData(); break; case R.id.login_setting: // 跳转到设置界面 SystemUtils.intentToAnotherActivity(LoginActivity.this, SettingActivity.class); break; default: break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.assigned_task_frames); Bundle extras = getIntent().getExtras(); groupName = extras.getString("groupname"); userName = extras.getString("userName"); param = new RequestParams(); param.add("groupname", groupName); invokeWSForGettingAssignedTasksToPersons(param, false, false); // Put ActionBar in Tab Mode tabBar = getSupportActionBar(); tabBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Store the list of tasks as an argument to the TaskFragment Bundle args = new Bundle(); args.putStringArrayList(TASK_IDS, mTaskIdsStringPending); args.putString(GROUP_NAME, groupName); args.putString(USER_NAME, userName); args.putStringArrayList(PERSON_IDS, mPersonsList); pendingFrag.setArguments(args); // Configure a tab for the Pending task TaskFragment tabBar.addTab( tabBar.newTab().setText("Pending tasks").setTabListener(new TabListener(pendingFrag))); // Store the list of tasks as an argument to the TaskFragment args = new Bundle(); args.putStringArrayList(TASK_IDS, mTaskIdsStringCompleted); args.putString(GROUP_NAME, groupName); args.putString(USER_NAME, userName); args.putStringArrayList(PERSON_IDS, mPersonsList); completedFrag.setArguments(args); // Configure a tab for the Completed tasks TaskFragment tabBar.addTab( tabBar.newTab().setText("Completed tasks").setTabListener(new TabListener(completedFrag))); }
@Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { showProgressDialog(); final ViewHolder holder = (ViewHolder) view.getTag(); AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); RequestParams rp = new RequestParams(); rp.add("id", holder.mId); asyncHttpClient.get( CommonDefine.SERVER + CommonDefine.HOUSE_INFO, rp, new TextHttpResponseHandler() { @Override public void onStart() { super.onStart(); } @Override public void onFailure(int i, Header[] headers, String s, Throwable throwable) { Log.e("xxxxx", "statusCode:" + i + "throwable:" + throwable); Toast.makeText(ResultActivity.this, R.string.net_err, Toast.LENGTH_SHORT).show(); } @Override public void onSuccess(int i, Header[] headers, String s) { Log.i("xxxxx", "s:" + s); Intent result = new Intent(ResultActivity.this, HouseActivity.class); result.putExtra(MainActivity.RESULT, s); startActivity(result); } @Override public void onFinish() { super.onFinish(); dismissProgressDialog(); } }); }
public void getData(final int page) { String uid = (CommonData.user.getUid() == null) ? "-1" : CommonData.user.getUid(); Log.d("Dfish", "uid = " + uid); params = new RequestParams(); params.add("uid", uid); params.add("type", "get_group_article_list"); params.add("gid", gid); Log.d("Dfish", "gid" + gid); params.add("page", "" + page); AsyncHttpClient client = new AsyncHttpClient(); PersistentCookieStore CStore = new PersistentCookieStore(context); // //HttpUtil.setCookieStore(CStore); // CStore.clear(); // HttpUtil.setCookieStore(CStore); // //HttpUtil.setCookieStore(context); HttpUtil.post( CommonData.groupURL, params, new TextHttpResponseHandler() { @Override public void onFailure( int statusCode, Header[] headers, String responseString, Throwable throwable) { Log.d("Dfish", "FF" + statusCode + headers); } @Override public void onSuccess(int statusCode, Header[] headers, String responseString) { Log.d("Dfish", "2" + responseString); isLoading = false; progressBar.setVisibility(View.GONE); if (page == 1) { topicList.clear(); } JSONObject resp = JSON.parseObject(responseString); List<Topic> topics = JsonParse.parseGroupArticles(resp); String concern = resp.getJSONObject("data").getString("concern"); canAnonymous = resp.getJSONObject("data").getJSONObject("group").getString("anonymous"); Log.d("Dfish", canAnonymous); if (concern.equals("1")) { fab.setVisibility(View.VISIBLE); flagConcern = true; } for (Topic topic : topics) { topicList.add(topic); } // topicList.addAll(topics); if (adapter == null) { adapter = new TopicAdapter(context, topicList); topicRv.setAdapter(adapter); } else { adapter.refreshData(topicList); } swipeRefresh.setRefreshing(false); adapter.setOnItemClickListener( new TopicAdapter.OnRecyclerViewItemClickListener() { @Override public void onItemClick(View v, String data, int flag) { String[] s = data.split("`"); Intent intent = new Intent(); Bundle localBundle = new Bundle(); switch (flag) { // click on username; case 2: intent.setClass(GroupActivity.this, UserInfoActivity.class); localBundle.putString("user_id", s[0]); localBundle.putString("title", s[1]); break; // click on group avatar case 1: intent.setClass(GroupActivity.this, GroupActivity.class); localBundle.putString("gid", s[0]); localBundle.putString("title", s[1]); break; case 0: intent.setClass(GroupActivity.this, ArticleActivity.class); localBundle.putString("g_a_id", s[0]); localBundle.putString("title", s[1]); break; default: break; } intent.putExtras(localBundle); GroupActivity.this.startActivity(intent); } }); } }); }
@Override public View onCreateView( final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View view = inflater.inflate(R.layout.my_feedback_main, container, false); myFeedBackListView = (ListView) view.findViewById(R.id.listViewFeedBack); arrayList = new ArrayList<>(); answerAdmin = new ArrayList<>(); RequestParams requestParams = new RequestParams(); JSONObject jsonCommand = new JSONObject(); try { jsonCommand.put("command", "myFeedbacks"); requestParams.add("data", jsonCommand.toString()); requestParams.add("userid", String.valueOf(1)); Log.i("JsonStr", jsonCommand.toString()); } catch (JSONException e) { e.printStackTrace(); } final TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice, tmSerial, androidId; tmDevice = "" + tm.getDeviceId(); tmSerial = "" + tm.getSimSerialNumber(); androidId = "" + android.provider.Settings.Secure.getString( getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); String deviceId = deviceUuid.toString(); Log.i("DeviceToken", deviceId); Log.i("PackageName", getActivity().getPackageName()); client.get( getActivity(), "http://88.198.48.246:9017/app/run", requestParams, new TextHttpResponseHandler() { @Override public void onFailure( int statusCode, Header[] headers, String responseString, Throwable throwable) { Log.e("statusCode", statusCode + ""); } @Override public void onSuccess(int statusCode, Header[] headers, String responseString) { Log.i("statusCode", statusCode + ""); Log.i("Response", responseString); try { JSONObject jsonObject = new JSONObject(responseString); if (jsonObject.getInt("status") == 200) { arrayList.clear(); JSONArray jsonArray = jsonObject.getJSONArray("requests"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonFeedBack = jsonArray.getJSONObject(i); String title = jsonFeedBack.getString("title"); String desc = jsonFeedBack.getString("descr"); String created = jsonFeedBack.getString("created"); if (jsonFeedBack.has("response")) { JSONObject answerObject = jsonFeedBack.getJSONObject("response"); answerAdmin.add(answerObject.getString("descr")); } if (jsonFeedBack.has("place") && jsonFeedBack.has("images") && jsonFeedBack.has("response")) { JSONArray jsonArrayImage = jsonFeedBack.getJSONArray("images"); JSONObject images = jsonArrayImage.getJSONObject(0); String imageUrl = images.getString("big"); JSONObject jsonObjectPlace = jsonFeedBack.getJSONObject("place"); JSONObject jsonObjectPlaceLog = jsonObjectPlace.getJSONObject("logo"); String logoUrl = jsonObjectPlaceLog.getString("big"); String placeName = jsonObjectPlace.getString("title"); String placeAddress = jsonObjectPlace.getString("address"); JSONObject answerObject = jsonFeedBack.getJSONObject("response"); String answerAdmin = answerObject.getString("descr"); arrayList.add( new MyFeedback( title, desc, created, imageUrl, logoUrl, placeName, answerAdmin, placeAddress)); Log.i("ImageHas", "+"); } else if (jsonFeedBack.has("place") && jsonFeedBack.has("images") && !jsonFeedBack.has("response")) { JSONObject jsonObjectPlace = jsonFeedBack.getJSONObject("place"); JSONObject jsonObjectPlaceLog = jsonObjectPlace.getJSONObject("logo"); String logoUrl = jsonObjectPlaceLog.getString("big"); String placeName = jsonObjectPlace.getString("title"); String placeAddress = jsonObjectPlace.getString("address"); JSONArray jsonArrayImage = jsonFeedBack.getJSONArray("images"); JSONObject images = jsonArrayImage.getJSONObject(0); String imageUrl = images.getString("big"); arrayList.add( new MyFeedback( title, desc, created, imageUrl, logoUrl, placeName, placeAddress)); } else if (jsonFeedBack.has("place") && !jsonFeedBack.has("images") && !jsonFeedBack.has("response")) { JSONObject jsonObjectPlace = jsonFeedBack.getJSONObject("place"); JSONObject jsonObjectPlaceLog = jsonObjectPlace.getJSONObject("logo"); String logoUrl = jsonObjectPlaceLog.getString("big"); String placeName = jsonObjectPlace.getString("title"); String placeAddress = jsonObjectPlace.getString("address"); arrayList.add( new MyFeedback(title, desc, created, logoUrl, placeName, placeAddress)); } else { arrayList.add(new MyFeedback(title, desc, created)); } } adapter = new MyFeedBackAdapter(getActivity(), arrayList); myFeedBackListView.setAdapter(adapter); } else { Toast.makeText(getActivity(), jsonObject.getString("message"), Toast.LENGTH_SHORT) .show(); } } catch (JSONException e) { e.printStackTrace(); } } }); myFeedBackListView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { sendNotification("SENDED"); Intent intent = new Intent(getActivity(), ShowFullFeedback.class); intent.putExtra("feedTitle", arrayList.get(position).getTitle()); intent.putExtra("feedDesc", arrayList.get(position).getDesc()); intent.putExtra("feedCreated", arrayList.get(position).getCreated()); intent.putExtra("feedPhoto", arrayList.get(position).getImageUrl()); intent.putExtra("placeLogo", arrayList.get(position).getLogoUrl()); intent.putExtra("placeName", arrayList.get(position).getPlaceName()); intent.putExtra("answerAdmin", arrayList.get(position).getAnswer()); intent.putExtra("placeAddress", arrayList.get(position).getAddress()); startActivity(intent); } }); return view; }