当前位置: 首页>>代码示例>>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;未经允许,请勿转载。