For the needs of the article we have created a demo app which is available on Github as well.

So without further ado, let’s dive in the actual implementation :)

Google Services Configuration File

To start using Google Services we first need to create a configuration file. This process has also been quite streamlined and it is just one click in order to download it. You can find detailed instructions here. After downloading it, place it inside your “app” folder and you are good to go :)

Google Sign-In

Google Sign-In, was previously known as Google+ Sign-In back in time, when Google required every new user to also create a Google+ social profile.

After Google dropped that requirement, all of their services were rebranded to plain Google, like Google Sign-In, for example.

As you can see at the bottom of the screenshot, this is the rebranded Google Sign-In button offered as a standalone view from Google.

Google Sign-In button (XML)

Now that we have added the Sign-In Button we need to configure it on our activity as well.

Google Sign-In button configuration

We also need to configure the GoogleApiClient, which will handle the Google Sign-In API and Credentials API requests:

Google API Client initial configuration

Let’s explain what these lines do:

addConnectionCallbacks → Makes the current Activity, aware of GoogleApiClient connection lifecycle. enableAutoManage → Let’s GoogleApiClient “hook” on the current Activity in order to manage the connect-disconnect operations based on the Activity’s lifecycle. addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions) → Here we are declaring that we will use the Google Sign-In API, with the GoogleSignOptions we have already created. addApi(Auth.CREDENTIALS_API) → We will also use the Credentials API for SmartLock, so we are declaring this one as well.

We are finally ready to proceed with the normal Google Sign-In flow. First step is to startActivityForResult with the Sign-In Intent when tapping on the Sign-In Button:

Initiate Google Sign-In

After that we are ready to handle the result in onActivityResult:

Google Sign-In Resolution handling

We can now process the result of Google Sign-In in order to update our UI. Depending on the result, we either sign-in the user or present him with a sign-up screen. All of these cases are implemented in detail on the demo project accompanying this article :)

SmartLock

SmartLock is a powerful password manager that Google provides through the same Google Account Login package in Play Services.

But what does SmartLock offer for us as developers and our end users?

SmartLock allows us to:

Ask users to save their credentials. Request those credentials when opening the app. Use credentials saved on Chrome, if we declare that our website and app can share credentials. Display email hints in case we want to help the user in the sign-in/sign-up process. Finally and most importantly, all of the above are stored on Google’s servers and users have complete control over what is saved/deleted.

We will cover all these cases in detail below, but if you think there might be something missing, please make sure to check the demo project on Github.