Courtesy: GitHub

compileSdkVersion 21

applicationId ""

minSdkVersion 9

targetSdkVersion 21

versionCode 1

versionName "1.0"

compile fileTree(dir: 'libs', include: ['*.jar'])

compile ''

// compile ''

compile ''

compile ''

compile ''



Copyright 2013, 2014 Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Google Play Services Accounts AutoManage sample. Demonstrates Google Sign-In and the usage of some of the Google APIs available in Google Play services. The application saves whether the user was last signed into the app to determine whether to try to sign them in again. The sample utilizes GoogleApiClient to store the Google Account selected by the user during sign-in. It also shows how to retrieve the associated Google Account ID. The Account ID should be used as the key to associate any local or remote data to the Google Account. This will ensure logout actions do not mix user data. Note that logout actions can occur without direct user intervention on this device, such as when a Google Account is assigned a new primary email address in Google for Work. This sample app WILL NOT WORK unless you have: 1.) Created an Application on the Google Developer Console 2.) Defined a Consent Screen in the Google Developer Console for your app. 3.) Registered your Android app's SHA1 certificate fingerprint and package name for your app (even for testing). 4.) Enabled the Google+ API in the Developer Console. Detailed instructions can be found here:

Preference that tracks whether the user is currently signed into the app. Specifically, if a user signs into the app via a Google Account and then comes back to it later this indicates they were last signed in. This preference is used to determine whether to initiate the GoogleApiClient connection immediately upon opening the activity. This logic prevents the user's first experience with your app from being an OAuth2 consent dialog.

GoogleApiClient is a service connection to Google Play services and provides access to the user's OAuth2 and API availability state for the APIs and scopes requested. Before making Google Play services API calls ensure {@code} returns true.

Construct a client using AutoManage functionality.

Delete user data to comply with using Google Account Terms and Conditions.

Called when the Activity successfully connects to Google Play Services. When the function is triggered, an account was selected on the device, the selected account has granted requested permissions to the app, and the app has established a connection to Google Play Services. * @param connectionHint can be inspected for additional connection info

The connection to Google Play services was lost for some reason, the auto management facility will try to reconnect automatically. This callback should be used to suspend use of the {@link GoogleApiClient} until it becomes connected again.

Called when the Activity could not connect to Google Play services AND the auto manager could not resolve the error automatically. * @param result can be inspected to determine the cause of the failure

Update the UI to reflect that the user is signed out of the app.

Update the UI to reflect that the user is signed into the app.

Returns whether the user is signed into the app.

Changes the user's app sign in state. * @param signedIn Whether the user is signed in.

Centralized location for dealing with GoogleApiClient connects or disconnects.