docs: Removing reference to Apache HTTP client

With Android M, the Apache HTTP client is no longer supported.
Removing references to that client and the clients that depend
on it (DefaultHttpClient and AndroidHttpClient). Replacing, when
appropriate, with references to HttpURLConnection.

Also removing references to the 2011 blog post "Android's HTTP
Clients" (https://goto.google.com/cusll) since that post is largely
about the ex-clients.

Fixed a couple of other small errors while I had the files open
(for example, changed a sample URL in a code snippet to the safe
www.example.com).

bug: 19696844
Change-Id: Iabf780140c37d5fc95c0d45542c425a945c69337
This commit is contained in:
Andrew Solovay
2015-09-24 11:52:48 -07:00
parent dcbd4ef241
commit d32f3baf2b
4 changed files with 18 additions and 58 deletions

View File

@ -7,21 +7,9 @@ page.landing.image=images/develop/connectivity.png
<div class="landing-docs">
<div class="col-6">
<h3>Blog Articles</h3>
<a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">
<h4>Androids HTTP Clients</h4>
<p>Most network-connected Android apps will use HTTP to send and receive data. Android
includes two HTTP clients: HttpURLConnection and Apache HTTP Client. Both support HTTPS, streaming
uploads and downloads, configurable timeouts, IPv6 and connection pooling.</p>
</a>
</div>
<div class="col-6">
<div>
<h3>Training</h3>
<a href="http://developer.android.com/training/efficient-downloads/index.html">
<h4>Transferring Data Without Draining the Battery</h4>
<p>This class demonstrates the best practices for scheduling and executing downloads using
@ -29,14 +17,14 @@ techniques such as caching, polling, and prefetching. You will learn how the pow
the wireless radio can affect your choices on when, what, and how to transfer data in order to
minimize impact on battery life.</p>
</a>
<a href="http://developer.android.com/training/cloudsync/index.html">
<h4>Syncing to the Cloud</h4>
<p>This class covers different strategies for cloud enabled applications. It covers syncing
data with the cloud using your own back-end web application, and backing up data using the cloud so
that users can restore their data when installing your application on a new device.</p>
</a>
</div>
</div>
</div>

View File

@ -376,9 +376,8 @@ support <a href="http://en.wikipedia.org/wiki/Server_Name_Indication">Server Nam
hostname to the server so the proper certificate can be returned.</p>
<p>Fortunately, {@link javax.net.ssl.HttpsURLConnection} supports
SNI since Android 2.3. Unfortunately, Apache
HTTP Client does not, which is one of the many reasons we discourage its use. One workaround
if you need to support Android 2.2 (and older) or Apache HTTP Client is to set up an alternative
SNI since Android 2.3. One workaround
if you need to support Android 2.2 (and older) is to set up an alternative
virtual host on a unique port so that it's unambiguous which server certificate to return.</p>
<p>The more drastic alternative is to replace {@link javax.net.ssl.HostnameVerifier}

View File

@ -49,14 +49,10 @@ application manifest must include the following permissions:</p>
<h2 id="http-client">Choose an HTTP Client</h2>
<p>Most network-connected Android apps use HTTP to send and receive data.
Android includes two HTTP clients: {@link java.net.HttpURLConnection} and the Apache HTTP client.
Both support HTTPS, streaming uploads and downloads, configurable
timeouts, IPv6, and connection pooling. We recommend using {@link
java.net.HttpURLConnection} for applications targeted at Gingerbread and higher. For
more discussion of this topic, see the blog post <a
href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html"
>Android's HTTP Clients</a>.</p>
<p>Most network-connected Android apps use HTTP to send and receive data. The
Android platform includes the {@link java.net.HttpURLConnection} client, which
supports HTTPS, streaming uploads and downloads, configurable timeouts,
IPv6, and connection pooling.</p>
<h2 id="connection">Check the Network Connection</h2>

View File

@ -39,36 +39,11 @@ as a singleton, which makes the {@code RequestQueue} last the lifetime of your a
of the requests, and a cache to handle caching. There are standard implementations of these
available in the Volley toolbox: {@code DiskBasedCache} provides a one-file-per-response
cache with an in-memory index, and {@code BasicNetwork} provides a network transport based
on your choice of the Apache HTTP client {@code android.net.http.AndroidHttpClient} or
{@link java.net.HttpURLConnection}.</p>
on your preferred HTTP client.</p>
<p>{@code BasicNetwork} is Volley's default network implementation. A {@code BasicNetwork}
must be initialized with the HTTP client your app is using to connect to the network.
Typically this is a {@link java.net.HttpURLConnection}:</p>
<ul>
<li>Use {@code android.net.http.AndroidHttpClient} for apps targeting Android API levels
lower than API Level 9 (Gingerbread). Prior to Gingerbread, {@link java.net.HttpURLConnection}
was unreliable. For more discussion of this topic, see
<a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">
Android's HTTP Clients</a>. </li>
<li>Use {@link java.net.HttpURLConnection} for apps targeting Android API Level 9
(Gingerbread) and higher.</li>
</ul>
<p>To create an app that runs on all versions of Android, you can check the version of
Android the device is running and choose the appropriate HTTP client, for example:</p>
<pre>
HttpStack stack;
...
// If the device is running a version >= Gingerbread...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
// ...use HttpURLConnection for stack.
} else {
// ...use AndroidHttpClient for stack.
}
Network network = new BasicNetwork(stack);
</pre>
Typically this is an {@link java.net.HttpURLConnection}.</p>
<p>This snippet shows you the steps involved in setting up a
{@code RequestQueue}:</p>
@ -88,7 +63,7 @@ mRequestQueue = new RequestQueue(cache, network);
// Start the queue
mRequestQueue.start();
String url ="http://www.myurl.com";
String url ="http://www.example.com";
// Formulate the request and handle the response.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
@ -107,7 +82,8 @@ StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
// Add the request to the RequestQueue.
mRequestQueue.add(stringRequest);
...
// ...
</pre>
<p>If you just need to make a one-time request and don't want to leave the thread pool
@ -198,7 +174,8 @@ class:</p>
// Get a RequestQueue
RequestQueue queue = MySingleton.getInstance(this.getApplicationContext()).
getRequestQueue();
...
// ...
// Add a request (in this example, called stringRequest) to your RequestQueue.
MySingleton.getInstance(this).addToRequestQueue(stringRequest);