Java Code Examples for com.loopj.android.http.AsyncHttpResponseHandler

The following examples show how to use com.loopj.android.http.AsyncHttpResponseHandler. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: UltimateAndroid   Author: cymcsg   File: HttpUtilsAsync.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP POST request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void postUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), responseHandler);
}
 
Example #2
Source Project: MiBandDecompiled   Author: vishnudevk   File: WebAPI.java    License: Apache License 2.0 6 votes vote down vote up
public static void getGameBriefInfo(AsyncHttpResponseHandler asynchttpresponsehandler)
{
    LoginData logindata = Keeper.readLoginData();
    RequestParams requestparams = BraceletHttpClient.getSysRp(logindata);
    String s = BraceletHttpClient.getUrl("huami.health.gethuodongconfig.json");
    HashMap hashmap = new HashMap();
    hashmap.put("userid", (new StringBuilder()).append("").append(logindata.uid).toString());
    hashmap.put("security", logindata.security);
    hashmap.put("v", "1.0");
    hashmap.put("appid", (new StringBuilder()).append("").append(ClientConstant.CLIENT_ID).toString());
    hashmap.put("callid", (new StringBuilder()).append("").append(System.currentTimeMillis()).toString());
    hashmap.put("lang", Locale.getDefault().getLanguage());
    BraceletHttpClient.getParamString(hashmap);
    Debug.i(TAG, (new StringBuilder()).append("game url =").append(s).toString());
    BraceletHttpClient.syncClient.post(s, requestparams, asynchttpresponsehandler);
}
 
Example #3
Source Project: MiBandDecompiled   Author: vishnudevk   File: WebAPI.java    License: Apache License 2.0 6 votes vote down vote up
public static void sendLoginResult(LoginInfo logininfo, String s, AsyncHttpResponseHandler asynchttpresponsehandler)
{
    RequestParams requestparams = new RequestParams();
    requestparams.put("access_token", (new StringBuilder()).append("").append(logininfo.accessToken).toString());
    requestparams.put("expiresIn", logininfo.expiresIn);
    requestparams.put("mac_token", logininfo.macToken);
    requestparams.put("miid", logininfo.miid);
    requestparams.put("aliasNick", logininfo.aliasNick);
    requestparams.put("miliaoNick", logininfo.miliaoNick);
    String s1;
    if (logininfo.miliaoIcon_320 != null && logininfo.miliaoIcon_320.length() > 0)
    {
        requestparams.put("miliaoIcon", logininfo.miliaoIcon_320);
    } else
    {
        requestparams.put("miliaoIcon", logininfo.miliaoIcon);
    }
    requestparams.put("friends", logininfo.friends);
    requestparams.put("deviceid", s);
    requestparams.put("devicetype", "0");
    s1 = BraceletHttpClient.getUrl("huami.health.apklogin.json");
    Debug.i(TAG, (new StringBuilder()).append("send login url= ").append(s1).toString());
    BraceletHttpClient.client.post(s1, requestparams, asynchttpresponsehandler);
}
 
Example #4
Source Project: UltimateAndroid   Author: cymcsg   File: HttpUtilsAsync.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP GET request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void getUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);
}
 
Example #5
Source Project: freeiot-android   Author: free-iot   File: DevicesApi.java    License: MIT License 6 votes vote down vote up
/**
 * /v1/devices/{identifier}/commands
    *
 * @param context
 * @param accessToken
 * @param identifier
 * @param jsonBody
 * @param responseHandler
 */
public static void sendCommands(Context context, String accessToken,
		String identifier, String jsonBody, AsyncHttpResponseHandler responseHandler) {
	List<Header> headerList = new ArrayList<Header>();
	headerList.add(new BasicHeader(ApiKey.HeadKey.ACCESS_TOKEN, accessToken));
	try {
		if (DEBUG) {
			LogUtils.d(jsonBody);
		}
		post(context,
                   String.format(getApiServerUrl() + DEVICE_SEND_COMMANDS, identifier)
                   , headerList, jsonBody, responseHandler);
	}  catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
}
 
Example #6
Source Project: freeiot-android   Author: free-iot   File: DevicesApi.java    License: MIT License 6 votes vote down vote up
/**
 * set device status (/v1/devices/{identifier}/status)
 * @param context
 * @param accessToken
 * @param identifier
 * @param responseHandler
 */
public static void setDeviceCurrentState(Context context, String accessToken,
      String identifier,String jsonBody, AsyncHttpResponseHandler responseHandler)
{
    List<Header> headerList = new ArrayList<Header>();
    headerList.add(new BasicHeader(ApiKey.HeadKey.ACCESS_TOKEN, accessToken));

    try
    {
        put(context, String.format(getApiServerUrl() + DEVICE_SET_CURRENT_STATUS, identifier),
                headerList, jsonBody, responseHandler);
    }
    catch (Exception e)
    {
        e.printStackTrace();
        responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
    }
}
 
Example #7
Source Project: iMoney   Author: xinpengfei520   File: WelcomeActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 更新APP
 */
private void updateApp() {
    startTime = System.currentTimeMillis(); // 获取系统当前的时间
    // 判断手机是否可以联网
    if (!NetStateUtil.isConnected(this)) {
        ToastUtil.show(WelcomeActivity.this, "网络异常!");
        toLoginPager();
    } else {
        String updateUrl = ApiRequestUrl.UPDATE; // 获取联网请求更新应用的路径
        // 使用AsyncHttpClient实现联网获取版本信息
        AsyncHttpClient client = new AsyncHttpClient();
        client.post(updateUrl, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String json) {
                LogUtils.json(TAG, json);
                // 使用fastJson解析json数据
                updateInfo = JSON.parseObject(json, UpdateInfo.class);
                handler.sendEmptyMessage(WHAT_DOWNLOAD_VERSION_SUCCESS);
            }

            @Override
            public void onFailure(Throwable error, String content) {
                LogUtils.e(TAG, "Throwable:" + error.getMessage() + ",content:" + content);
                ToastUtil.show(WelcomeActivity.this, "联网获取更新数据失败!");
                toLoginPager();
            }
        });
    }
}
 
Example #8
Source Project: monolog-android   Author: huijimuhe   File: BaseClient.java    License: MIT License 5 votes vote down vote up
public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    if (!AppContext.getInstance().isConnected()) {
        ToastUtils.show(AppContext.getInstance(), AppContext.getInstance().getString(R.string.error_no_network));
        return;
    }
    client.get(getAbsoluteUrl(url), params, responseHandler);
}
 
Example #9
Source Project: monolog-android   Author: huijimuhe   File: BaseClient.java    License: MIT License 5 votes vote down vote up
public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    if (!AppContext.getInstance().isConnected()) {
        ToastUtils.show(AppContext.getInstance(), AppContext.getInstance().getString(R.string.error_no_network));
        return;
    }
    client.post(getAbsoluteUrl(url), params, responseHandler);
}
 
Example #10
Source Project: UltimateAndroid   Author: cymcsg   File: HttpUtilsAsync.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Perform a HTTP GET request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param responseHandler
 */
public static void getWithCookie(Context context, String url, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    //  myCookieStore.clear();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);

}
 
Example #11
Source Project: foodie-app   Author: Sambor123   File: HttpUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void postWithAuth(Context context,String url, RequestParams params,AsyncHttpResponseHandler responseHandler) {
    String JSESSIONID=PrefUtils.get("user","session",context);
    Log.i("session","提交"+JSESSIONID);
    //client.setBasicAuth("18813073333","123456");
    client.addHeader("Cookie", "JSESSIONID="+JSESSIONID);
    client.post(getAbsoluteUrl(url), params, responseHandler);
}
 
Example #12
Source Project: foodie-app   Author: Sambor123   File: HttpUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void postWithAuth(Context context, String url, AsyncHttpResponseHandler responseHandler) {
    String JSESSIONID = PrefUtils.get("user", "session", context);
    Log.i("session", "提交" + JSESSIONID);
    //client.setBasicAuth("18813073333","123456");
    client.addHeader("Cookie", "JSESSIONID=" + JSESSIONID);
    client.post(getAbsoluteUrl(url), responseHandler);
}
 
Example #13
Source Project: foodie-app   Author: Sambor123   File: HttpUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void getWithAuth(Context context, String url, AsyncHttpResponseHandler asyncHttpResponseHandler) {
    String JSESSIONID = PrefUtils.get("user", "session", context);
    Log.i("session", "提交" + JSESSIONID);
    //client.setBasicAuth("18813073333","123456");
    client.addHeader("Cookie", "JSESSIONID=" + JSESSIONID);
    client.get(getAbsoluteUrl(url), asyncHttpResponseHandler);
}
 
Example #14
Source Project: pusher-websocket-android   Author: pusher   File: TokenRegistry.java    License: MIT License 5 votes vote down vote up
private void update(String token, String cachedId) throws JSONException {
    String url = options.buildNotificationURL("/clients/" + cachedId + "/token");
    AsyncHttpClient client = factory.newHttpClient();
    StringEntity params = createRegistrationJSON(token);

    AsyncHttpResponseHandler handler = factory.newTokenUpdateHandler(
            cachedId, params, context, listenerStack, this
    );
    client.put(context, url, params, "application/json", handler);
}
 
Example #15
Source Project: AndroidStudyDemo   Author: DIY-green   File: AAHTestApi.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void postFile(String url, File file, AsyncHttpResponseHandler handler) {
    try {
        AsyncHttpUtil.upLoadFile(url, file, handler);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example #16
Source Project: AndroidStudyDemo   Author: DIY-green   File: AAHTestApi.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void getUser(String url, Map<String, String> params, AsyncHttpResponseHandler handler) {
    RequestParams requestParams = new RequestParams();
    if (params != null) {
        for (String key : params.keySet()) {
            requestParams.put(key, params.get(key));
        }
    }
    AsyncHttpUtil.post(url, requestParams, handler);
}
 
Example #17
Source Project: AndroidStudyDemo   Author: DIY-green   File: AAHTestApi.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void uploadFile(String url, File file, AsyncHttpResponseHandler handler) {
    try {
        AsyncHttpUtil.upLoadFile(url, file, handler);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example #18
Source Project: AndroidStudyDemo   Author: DIY-green   File: AsyncHttpUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 上传文件
 *
 * @return
 */
public static void upLoadFile(String url, File file, AsyncHttpResponseHandler handler) throws FileNotFoundException {
    RequestParams params = new RequestParams();
    params.put("username", "张鸿洋");
    params.put("password", "123");
    params.put("mFile", file);
    AsyncHttpClient client = getHttpClient();
    client.addHeader("Content-disposition", "mFile=\"" + file.getName() + "\"");
    client.addHeader("APP-Key", "APP-Secret222");
    client.addHeader("APP-Secret", "APP-Secret111");
    client.post(url, params, handler);
}
 
Example #19
Source Project: school_shop   Author: Owater   File: UserReplyActivity.java    License: MIT License 5 votes vote down vote up
private void getNetData() {
	RequestParams params = new RequestParams();
	params.add("userId", MyApplication.userInfo[1]);
	params.add("authCode", MyApplication.userInfo[0]);
	String url = null;
	if(choose==0) {
		url=URLs.USERRELY;
		isMe = false;
	}else {
		url=URLs.USERJOINTHEME;
		isMe = true;
	}
	networkHelper.getNetJson(url, params, new AsyncHttpResponseHandler(){
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
			Gson gson = new Gson();
			DataJson dataJson = gson.fromJson(new String(responseBody), DataJson.class);
			if (dataJson.isSuccess()) {
				list = gson.fromJson(gson.toJson(dataJson.getData()), new TypeToken<List<GoodsCommentEntity>>(){}.getType());
				initAdapter();
			}else {
				showButtomToast("用户信息有误");
			}
			loadingProgressDialog.dismiss();
		}
		
		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
			loadingProgressDialog.dismiss();
		}
	});
}
 
Example #20
Source Project: school_shop   Author: Owater   File: UserDetailActivity.java    License: MIT License 5 votes vote down vote up
private void initQiniuToken(){
	MarketPubActivity.qiniuToken = null;
	networkHelper.getNetString(URLs.QINIU_TOKEN, new AsyncHttpResponseHandler() {
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
			MarketPubActivity.qiniuToken = new String(responseBody);
		}
		
		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
		}
	});
}
 
Example #21
Source Project: school_shop   Author: Owater   File: MarketPubActivity.java    License: MIT License 5 votes vote down vote up
private void initQiniuToken(){
	networkHelper.getNetString(URLs.QINIU_TOKEN, new AsyncHttpResponseHandler() {
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
			qiniuToken = new String(responseBody);
		}
		
		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
		}
	});
}
 
Example #22
Source Project: school_shop   Author: Owater   File: SetPasswordActivity.java    License: MIT License 5 votes vote down vote up
public void postData(){
	RequestParams params = new RequestParams();
	params.put("authCode", MyApplication.userInfo[0]);
	params.put("userId", MyApplication.userInfo[1]);
	params.put("phone", MyApplication.userInfo[3]);
	try {
           String oldPwd = oldPassword.getText().toString();
           String newPwd = newPassword.getText().toString();
           String confirmPwd = confirmPassword.getText().toString();
           if (passwordFormatError(oldPwd, newPwd, confirmPwd)) {
               return;
           }
           params.put("oldPassword", PBEUtil.encrypt(oldPwd, PBEUtil.passwordkey, PBEUtil.getStaticSalt()));
           params.put("newPassword", PBEUtil.encrypt(newPwd, PBEUtil.passwordkey,PBEUtil.getStaticSalt()));
           networkHelper.getNetJson(URLs.USER_RESETPWD, params, new AsyncHttpResponseHandler(){
           	
           	@Override
			public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
           		Gson gson = new Gson();
   				DataJson dataJson = gson.fromJson(new String(responseBody), DataJson.class);
   				if (dataJson.isSuccess()) {
   					showButtomToast("密码修改成功");
   					popDialog();
   				}else {
   					showButtomToast(dataJson.getMsg());
				}
			}

			@Override
			public void onFailure(int arg0, Header[] arg1, byte[] arg2,
					Throwable arg3) {
			}

           });
       } catch (Exception e) {
       	showButtomToast(e.toString());
       }
}
 
Example #23
Source Project: school_shop   Author: Owater   File: MarkSubmitActivity.java    License: MIT License 5 votes vote down vote up
private void initQiniuToken(){
	MarketPubActivity.qiniuToken = null;
	networkHelper.getNetString(URLs.QINIU_TOKEN, new AsyncHttpResponseHandler() {
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
			MarketPubActivity.qiniuToken = new String(responseBody);
		}
		
		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
		}
	});
}
 
Example #24
Source Project: freeiot-android   Author: free-iot   File: UserApi.java    License: MIT License 5 votes vote down vote up
/**
 * user logout (/v1/users/logout)
 * @param context
 * @param accessToken
 * @param responseHandler
 */
public static void logout(Context context, String accessToken, AsyncHttpResponseHandler responseHandler) {
    List<Header> headerList = new ArrayList<Header>();
    headerList.add(new BasicHeader(ApiKey.HeadKey.ACCESS_TOKEN, accessToken));
    try {
        post(context, getApiServerUrl() + USER_LOGOUT, headerList, null, responseHandler);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
    }
}
 
Example #25
Source Project: school_shop   Author: Owater   File: UserPubGoodsActivity.java    License: MIT License 5 votes vote down vote up
private void loadData() {
	loadingProgressDialog.show();
	RequestParams params = new RequestParams();
	if (!isMe) {
		params.add("otherUserId", otherUserId);
	}
	params.add("userId", MyApplication.userInfo[1]);
	params.add("authCode", MyApplication.userInfo[0]);
	params.add("type", type);
	networkHelper.getNetJson(URLs.USER_PUB_GOODS, params, new AsyncHttpResponseHandler(){
		
		@Override
		public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
			Gson gson = new Gson();
			DataJson dataJson = gson.fromJson(new String(responseBody), DataJson.class);
			if(dataJson.isSuccess()){
				 if(type.equals("userGoods")||type.equals("like")){
					 goodsList = gson.fromJson(gson.toJson(dataJson.getData()), new TypeToken<List<GoodsEntity>>(){}.getType());
					 if(goodsList!=null) initAdapter(); else showButtomToast(getStringByRId(R.string.dataError));
				 }else if (type.equals("userShare")) {
					 shareList = gson.fromJson(gson.toJson(dataJson.getData()), new TypeToken<List<ShareEntity>>(){}.getType());
					 if(shareList!=null) initAdapter(); else showButtomToast(getStringByRId(R.string.dataError));
				}
			}else {
				showButtomToast(getStringByRId(R.string.dataError));
			}
			loadingProgressDialog.dismiss();
		}
		
		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
			loadingProgressDialog.dismiss();
		}
	});
}
 
Example #26
Source Project: MiBandDecompiled   Author: vishnudevk   File: WebAPI.java    License: Apache License 2.0 5 votes vote down vote up
public static void getGameRegisterInfo(AsyncHttpResponseHandler asynchttpresponsehandler)
{
    RequestParams requestparams = BraceletHttpClient.getSysRp(Keeper.readLoginData());
    String s = BraceletHttpClient.getUrl("huami.health.detectuserwhetherjoinhuodong.json");
    Debug.i(TAG, (new StringBuilder()).append("game register url =").append(s).toString());
    BraceletHttpClient.syncClient.post(s, requestparams, asynchttpresponsehandler);
}
 
Example #27
Source Project: MiBandDecompiled   Author: vishnudevk   File: WebAPI.java    License: Apache License 2.0 5 votes vote down vote up
public static void getUserInfo(LoginData logindata, long l, AsyncHttpResponseHandler asynchttpresponsehandler)
{
    RequestParams requestparams = BraceletHttpClient.getSysRp(logindata);
    requestparams.put("uid", (new StringBuilder()).append("").append(l).toString());
    String s = BraceletHttpClient.getUrl("huami.health.getUserInfo.json");
    BraceletHttpClient.client.post(s, requestparams, asynchttpresponsehandler);
}
 
Example #28
Source Project: MiBandDecompiled   Author: vishnudevk   File: WebAPI.java    License: Apache License 2.0 5 votes vote down vote up
public static void getWeixinQR(LoginData logindata, String s, AsyncHttpResponseHandler asynchttpresponsehandler)
{
    RequestParams requestparams = BraceletHttpClient.getSysRp(logindata);
    requestparams.put("deviceid", s);
    String s1 = BraceletHttpClient.getUrl("huami.health.createwxqr.json");
    BraceletHttpClient.client.post(s1, requestparams, asynchttpresponsehandler);
}
 
Example #29
Source Project: MiBandDecompiled   Author: vishnudevk   File: WebAPI.java    License: Apache License 2.0 5 votes vote down vote up
public static void sendFeedback(LoginData logindata, String s, String s1, AsyncHttpResponseHandler asynchttpresponsehandler)
{
    RequestParams requestparams = BraceletHttpClient.getSysRp(logindata);
    requestparams.put("message", s);
    requestparams.put("email", s1);
    String s2 = BraceletHttpClient.getUrl("huami.health.report.json");
    BraceletHttpClient.client.post(s2, requestparams, asynchttpresponsehandler);
}
 
Example #30
Source Project: MiBandDecompiled   Author: vishnudevk   File: WebAPI.java    License: Apache License 2.0 5 votes vote down vote up
public static void sendLocation(LoginData logindata, UserLocationData userlocationdata, AsyncHttpResponseHandler asynchttpresponsehandler)
{
    RequestParams requestparams = BraceletHttpClient.getSysRp(logindata);
    String s;
    try
    {
        requestparams.put("location", (new StringBuilder()).append("").append(URLEncoder.encode(userlocationdata.toString(), "utf-8")).toString());
    }
    catch (UnsupportedEncodingException unsupportedencodingexception)
    {
        unsupportedencodingexception.printStackTrace();
    }
    s = BraceletHttpClient.getUrl("huami.health.backup.json");
    BraceletHttpClient.client.post(s, requestparams, asynchttpresponsehandler);
}