Android AndroidHttpClient - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AndroidHttpClient class.

This code example shows how to use the following methods:close, execute, getParams
      ByteArrayEntity entity = new ByteArrayEntity(mms);
 
      entity.setContentType("application/vnd.wap.mms-message");
 
      request.setEntity(entity);
      request.setParams(client.getParams());
      request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
//      request.addHeader("x-wap-profile", "http://www.htcmms.com.tw/Android/Common/nexusone/ua-profile.xml"); 
      request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
      HttpResponse response = client.execute(target, request);
      StatusLine status     = response.getStatusLine();
 
      if (status.getStatusCode() != 200)
        throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase());
 
      return parseResponse(response.getEntity());
    } catch (URISyntaxException use) {
      Log.w("MmsSendHelper", use);
      throw new IOException("Couldn't parse URI.");
    } finally { 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageManager, getPackageName, getString, newInstance
	} 
 
	private <T> T doRequest(HttpRequestBase request, ResponseHandler<T> responseHandler) {
		mHttpRequest = request;
 
		AndroidHttpClient client = AndroidHttpClient.newInstance(getUserAgent(), mContext);
		AndroidHttpClient.modifyRequestToAcceptGzipResponse(mHttpRequest);
 
		HttpParams httpParameters = client.getParams();
		HttpConnectionParams.setSoTimeout(httpParameters, 100000);
 
		try { 
			return client.execute(mHttpRequest, responseHandler);
		} 
		catch (IOException e) {
			Log.e("Server request failed.", e);
		} 
		finally { 
			client.close();
		} 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
	        is.close();
	     } catch (Exception e) {
	    	e.printStackTrace();
	     } finally { 
	    	 if (httpclient != null) {
	    	   httpclient.close();
	    	 } 
	     } 
	     return bm;
	} 
     
    static class FlushedInputStream extends FilterInputStream {
        public FlushedInputStream(InputStream inputStream) {
            super(inputStream);
        } 
 
        @Override 
        public long skip(long n) throws IOException {
            long totalBytesSkipped = 0L;
            while (totalBytesSkipped < n) {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getParams
    private final AndroidHttpClient mHttpClient;
 
    public OpenSearchSearchEngine(Context context, SearchEngineInfo searchEngineInfo) {
        mSearchEngineInfo = searchEngineInfo;
        mHttpClient = AndroidHttpClient.newInstance(USER_AGENT);
        HttpParams params = mHttpClient.getParams();
        params.setLongParameter(HTTP_TIMEOUT, HTTP_TIMEOUT_MS);
    } 
 
    public String getName() {
        return mSearchEngineInfo.getName();
    } 
 
    public CharSequence getLabel() {
        return mSearchEngineInfo.getLabel();
    } 
 
    public void startSearch(Context context, String query, Bundle appData, String extraData) {
        String uri = mSearchEngineInfo.getSearchUriForQuery(query);
        if (uri == null) {
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
     * @param instance HttpClient 
     */ 
    public static void closeInstance(HttpClient instance) {
        if (instance instanceof AndroidHttpClient) {
            AndroidHttpClient client = (AndroidHttpClient) instance;
            client.close();
        } else { 
            ClientConnectionManager mgr = instance.getConnectionManager();
            if (mgr != null)
                mgr.shutdown();
        } 
    } 
 
    public static void setUserAgentString(String userAgent) {
    	sUserAgent = userAgent;
    } 
     
    public static String getUserAgentString() {
        return sUserAgent;
    } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:execute
     * @return The execution resonse. 
     * @throws ClientProtocolException 
     * @throws IOException 
     */ 
    protected Execution execute(HttpRequestBase req) throws ClientProtocolException, IOException {
        HttpResponse res = http.execute(req);
        HttpEntity entity = res.getEntity();
        if (entity != null) {
            // Wrapping response entity to handle gzip decompression transparently 
            // Note: AndroidHttpClient doesn't let you add response interceptors to the underlying DefaultHttpClient 
            res.setEntity(new GzipDecompressingEntity(res.getEntity()));
        } 
        return new Execution(req, res);
    } 
 
    /** 
     * @param req 
     * @param headers 
     */ 
    private void addHeaders(HttpRequestBase req, Map<String, String> headers) {
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally { 
            if (httpclient != null) {
                httpclient.close();
            } 
        } 
        return bm;
    } 
 
    static class FlushedInputStream extends FilterInputStream {
        public FlushedInputStream(InputStream inputStream) {
            super(inputStream);
        } 
 
        @Override 
        public long skip(long n) throws IOException {
            long totalBytesSkipped = 0L;
            while (totalBytesSkipped < n) {
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally { 
            if (httpclient != null) {
                httpclient.close();
            } 
        } 
        return bm;
    } 
 
    static class FlushedInputStream extends FilterInputStream {
        public FlushedInputStream(InputStream inputStream) {
            super(inputStream);
        } 
 
        @Override 
        public long skip(long n) throws IOException {
            long totalBytesSkipped = 0L;
            while (totalBytesSkipped < n) {
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally { 
            if (httpclient != null) {
                httpclient.close();
            } 
        } 
        return bm;
    } 
 
    static class FlushedInputStream extends FilterInputStream {
        public FlushedInputStream(InputStream inputStream) {
            super(inputStream);
        } 
 
        @Override 
        public long skip(long n) throws IOException {
            long totalBytesSkipped = 0L;
            while (totalBytesSkipped < n) {
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
		return _hrh;
	} 
	 
	public void finalize() { 
		// don't leak; 
		client.close();
	} 
	 
	 
	public static boolean isNetworkAvailable(Context ctx) {
		// Requires NETWORK_STATE permissions 
	    ConnectivityManager cm = (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
	    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
	    // if no network is available networkInfo will be null 
	    // otherwise check if we are connected 
	    if (networkInfo != null && networkInfo.isConnected()) {
	        return true; 
	    } 
	    return false; 
	} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android AndroidHttpClient Questions & Answers:

See Code Examples for Android AndroidHttpClient Methods: