Merge "Updates Google Play Services section with instructions for calling connect(). Staged: http://wfrench.kir.corp.google.com:9000/training/location/retrieve-current.html" into mnc-docs

This commit is contained in:
William French
2015-12-07 23:33:50 +00:00
committed by Android (Google) Code Review

View File

@@ -71,8 +71,8 @@ trainingnavtop=true
block.</p>
<p>This lesson requires only coarse location. Request this permission with the
{@code uses-permission} element in your app manifest, as shown in the
following example:
{@code uses-permission} element in your app manifest, as the following code
snippet shows:
<pre>
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
@@ -92,18 +92,15 @@ trainingnavtop=true
</p>
<p>In your activity's {@link android.app.Activity#onCreate onCreate()} method,
create an instance of Google API Client using
<a href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient.Builder.html">{@code GoogleApiClient.Builder}</a>.
Use the builder to add the
<a href="{@docRoot}reference/com/google/android/gms/location/LocationServices.html">{@code LocationServices}</a>
API.</p>
<p>The sample app defines a {@code buildGoogleApiClient()} method, called from
the activity's {@link android.app.Activity#onCreate onCreate()} method,
which includes the following code.</p>
create an instance of Google API Client, using the
<a href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient.Builder.html">{@code GoogleApiClient.Builder}</a> class to add the
<a href="{@docRoot}reference/com/google/android/gms/location/LocationServices.html">
{@code LocationServices}</a>
API, as the following code snippet shows.</p>
<pre>
protected synchronized void buildGoogleApiClient() {
// Create an instance of GoogleAPIClient.
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
@@ -112,6 +109,31 @@ protected synchronized void buildGoogleApiClient() {
}
</pre>
<p>To connect, call
<a href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient#connect()">
{@code connect()}</a>
from the activity's
<a href="{@docRoot}reference/android/app/Activity.html#onStart()">{@code onStart()}</a>
method. To disconnect, call
<a href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient#disconnect()">
{@code disconnect()}</a> from the activity's
<a href="{@docRoot}reference/android/app/Activity.html#onStop()">
{@code onStop()}</a> method. The following snippet shows an example of how
to use both of these methods.
</p>
<pre>
protected void onStart() {
mGoogleApiClient.connect();
super.onStart();
}
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
</pre>
<h2 id="last-known">Get the Last Known Location</h2>
<p>Once you have connected to Google Play services and the location services
@@ -130,7 +152,7 @@ protected synchronized void buildGoogleApiClient() {
object. Do this in the
<a href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient.ConnectionCallbacks.html#onConnected(android.os.Bundle)">{@code onConnected()}</a>
callback provided by Google API Client, which is called when the client is
ready. The following code sample illustrates the request and a simple
ready. The following code snippet illustrates the request and a simple
handling of the response:</p>
<pre>