當前位置: 首頁>>代碼示例>>Java>>正文


Java AndroidHttpClient.newInstance方法代碼示例

本文整理匯總了Java中android.net.http.AndroidHttpClient.newInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java AndroidHttpClient.newInstance方法的具體用法?Java AndroidHttpClient.newInstance怎麽用?Java AndroidHttpClient.newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.http.AndroidHttpClient的用法示例。


在下文中一共展示了AndroidHttpClient.newInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newRequestQueue

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:36,代碼來源:Volley.java

示例2: downloadUriAsString

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
private static String downloadUriAsString(final HttpUriRequest req)
    throws IOException {
  AndroidHttpClient client = AndroidHttpClient.newInstance(userAgentString());
  try {
    HttpResponse res = client.execute(req);
    return readToEnd(res.getEntity().getContent());
  } finally {
    client.close();
  }
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:11,代碼來源:SocketIOClient.java

示例3: createHttpClient

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
private static AndroidHttpClient createHttpClient(Context context) {
    String userAgent = MmsConfig.getUserAgent();
    AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, context);
    HttpParams params = client.getParams();
    HttpProtocolParams.setContentCharset(params, "UTF-8");

    // set the socket timeout
    int soTimeout = MmsConfig.getHttpSocketTimeout();

    if (DEBUG) {
        Log.d(TAG, "[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, "
                + ", UA=" + userAgent);
    }
    HttpConnectionParams.setSoTimeout(params, soTimeout);
    return client;
}
 
開發者ID:ivanovpv,項目名稱:darksms,代碼行數:17,代碼來源:HttpUtils.java

示例4: getDefaultStack

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
private static HttpStack getDefaultStack(Context context){
    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();

        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }
    
    if (Build.VERSION.SDK_INT >= 9) {
       return new HurlStack();
    } else {
        // Prior to Gingerbread, HttpUrlConnection was unreliable.
        // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
        return new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
    }    	
}
 
開發者ID:active-citizen,項目名稱:android.java,代碼行數:19,代碼來源:Volley.java

示例5: doInBackground

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
@Override
protected String doInBackground( Void... params )
{
	AndroidHttpClient httpClient = AndroidHttpClient.newInstance( "" );
	HttpGet get = new HttpGet( URL );

	try
	{
		HttpResponse response = httpClient.execute( get );
		HttpEntity entity = response.getEntity( );
		InputStreamReader reader = new InputStreamReader( entity.getContent( ) );
		BufferedReader bufReader = new BufferedReader( reader );

		String status = bufReader.readLine( );
		entity.consumeContent( );

		return status;
	}
	catch ( Exception e )
	{
		Log.e( "WIDGET", e.getMessage( ) );
	}

	return "No status received";
}
 
開發者ID:DerGary,項目名稱:FHWS-MobileApplikationen,代碼行數:26,代碼來源:DemoAppWidget.java

示例6: download

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
private HttpResponse download() throws IOException {

        httpClient = AndroidHttpClient.newInstance("Android");
        // httpClient.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost("127.0.0.1"));

        URL netUrl = proxyInfo.netUrl;
        HttpHost host = new HttpHost(netUrl.getHost(), netUrl.getPort(), netUrl.getProtocol());

        HttpRequestBase request = new HttpGet(netUrl.toString());
        HttpResponse response = null;
        Log.d(TAG, "Proxy starting download");
        if (authType == AuthType.Digest) {
            HttpContext context = HttpHelper.getDigestAuthContext(netUrl.getHost(), netUrl.getPort(), proxyInfo.user, proxyInfo.password);
            response = httpClient.execute(host, request, context);
        }
        else if (authType == AuthType.Basic) {
            String credentials = Base64.encodeToString((proxyInfo.user + ":" + proxyInfo.password).getBytes(), Base64.DEFAULT);
            request.setHeader("Authorization", "Basic " + credentials);
            response = httpClient.execute(host, request);
        }
        else {
            response = httpClient.execute(host, request);
        }
        Log.d(TAG, "Proxy response downloaded");
        return response;
    }
 
開發者ID:oakesville,項目名稱:mythling,代碼行數:27,代碼來源:MediaStreamProxy.java

示例7: doRequest

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
private static BackendConnectionResult doRequest(HttpUriRequest request) {
    RequestAnalytics analytics = new RequestAnalytics(request);
    AndroidHttpClient httpClient = AndroidHttpClient.newInstance(userAgent);
    BackendConnectionResult result;
    try {
        HttpResponse response = httpClient.execute(request);
        InputStream inputStream = response.getEntity().getContent();
        StatusLine statusLine = response.getStatusLine();
        
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charsets.UTF_8);
        String contentString = CharStreams.toString(inputStreamReader);
        inputStreamReader.close();
        
        httpClient.close();
        result = new BackendConnectionResult(statusLine, contentString);
    } catch (IOException e) {
        result = new BackendConnectionResult(e);
    }
    analytics.done(result);
    return result;
}
 
開發者ID:antonyt,項目名稱:TflTravelAlerts,代碼行數:22,代碼來源:BackendConnection.java

示例8: createHttpClient

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
private static AndroidHttpClient createHttpClient(Context context) {
    String userAgent = MmsConfig.getUserAgent();
    AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, context);
    HttpParams params = client.getParams();
    HttpProtocolParams.setContentCharset(params, "UTF-8");

    // set the socket timeout
    int soTimeout = MmsConfig.getHttpSocketTimeout();

    if (Log.isLoggable(LogTag.TRANSACTION, Log.DEBUG)) {
        Log.d(TAG, "[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, "
                + ", UA=" + userAgent);
    }
    HttpConnectionParams.setSoTimeout(params, soTimeout);
    return client;
}
 
開發者ID:slvn,項目名稱:android-aosp-mms,代碼行數:17,代碼來源:HttpUtils.java

示例9: DownloadService

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
/**
	 * initialize http client
	 */
	public DownloadService() {
//		HttpParams params = new BasicHttpParams();
//		HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
//		HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
//		HttpProtocolParams.setUseExpectContinue(params, false);
//		ConnManagerParams.setMaxTotalConnections(params, 10);
//		HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
//		HttpConnectionParams.setSoTimeout(params, 10 * 1000);
//
//		SchemeRegistry schReg = new SchemeRegistry();
//		schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
//		schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

		httpClient = AndroidHttpClient.newInstance("stockanalyze,gzip");
		HttpClientParams.setRedirecting(httpClient.getParams(), true);
	}
 
開發者ID:kultus,項目名稱:StockAnalyze,代碼行數:20,代碼來源:DownloadService.java

示例10: HttpGetAnswer

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
public static String HttpGetAnswer(String url) throws ClientProtocolException, IOException, JSONException, HttpException{
	AndroidHttpClient client = AndroidHttpClient.newInstance(null);
	client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 7500);
	client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 7500);
	HttpGet httpGet = new HttpGet(url);
	HttpResponse response = client.execute(httpGet);
	StatusLine statusLine = response.getStatusLine();
	int statusCode = statusLine.getStatusCode();
	if (statusCode == 200) {
		String resp = EntityUtils.toString(response.getEntity());
		client.close();
		return resp;
	} else {
		try {
			client.close();
		}catch (Exception ex){}
		throw new HttpException("STATUSCODE!=200");
	}
}
 
開發者ID:nibdev,項目名稱:otrta,代碼行數:20,代碼來源:ServiceData.java

示例11: newRequestQueue

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
private static RequestQueue newRequestQueue(Context context) {

        // On HC+ use HurlStack which is based on HttpURLConnection. Otherwise fall back on
        // AndroidHttpClient (based on Apache DefaultHttpClient) which should no longer be used
        // on newer platform versions where HttpURLConnection is simply better.
        Network network = new BasicNetwork(
                UIUtils.hasHoneycomb() ?
                        new HurlStack() :
                        new HttpClientStack(AndroidHttpClient.newInstance(
                                NetUtils.getUserAgent(context))));

        Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR));
        RequestQueue queue = new RequestQueue(cache, network);
        queue.start();
        return queue;
    }
 
開發者ID:TheDeltaProgram,項目名稱:iosched2013,代碼行數:17,代碼來源:ImageLoader.java

示例12: newRequestQueue

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:35,代碼來源:Volley.java

示例13: newRequestQueue

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "com/android/volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
 
開發者ID:Rabbit00,項目名稱:MeifuGO,代碼行數:36,代碼來源:Volley.java

示例14: newRequestQueue

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 * You may set a maximum size of the disk cache in bytes.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @param maxDiskCacheBytes the maximum size of the disk cache, in bytes. Use -1 for default size.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack, int maxDiskCacheBytes) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }
    
    Network network = new BasicNetwork(stack);
    
    RequestQueue queue;
    if (maxDiskCacheBytes <= -1)
    {
    	// No maximum size specified
    	queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    }
    else
    {
    	// Disk cache size specified
    	queue = new RequestQueue(new DiskBasedCache(cacheDir, maxDiskCacheBytes), network);
    }

    queue.start();

    return queue;
}
 
開發者ID:LifengMr,項目名稱:apker,代碼行數:49,代碼來源:Volley.java

示例15: newRequestQueue

import android.net.http.AndroidHttpClient; //導入方法依賴的package包/類
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack   An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread-Android2.3, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
 
開發者ID:why168,項目名稱:AndroidProjects,代碼行數:36,代碼來源:Volley.java


注:本文中的android.net.http.AndroidHttpClient.newInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。