This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video

00:00
00:00
00:00
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Learn how to add the Google Play Services Code Library and add permissions to the Android Manifest.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now let's finish the setup by adding
in the final pieces to our Android
0:00
studio project.
0:05
Google has a code library to
access Google play services,
0:06
which we'll add with a small
change to our build.dreidel file.
0:09
We'll also need to add some
permissions to the Android manifest.
0:14
First, we need to ensure
the code libraries for
0:18
Google Play Services are downloaded and
up to date.
0:20
We can do this by opening the SDK Manager
and scrolling down to the extra section.
0:23
Ensure the Google Repository,
Google Play Services,
0:30
Android Support Library and Android
Support Repository are all up to date.
0:34
If updates are available,
go ahead and download them now.
0:40
Everything is up to date, so
let's close this window and
0:43
head to the Android manifest.
0:45
We need to add in a metadata tag.
0:47
This tag will store the version of Google
Play Services where building our app with.
0:49
Google Play Services will check this
value when the app requests an API and
0:54
if the Google Play Services on the device
matches the number, it will proceed.
0:58
If it doesn't match and needs updating,
1:02
it'll prompt the user to
update through Play Store.
1:04
We just added as a metadata
tag within our application.
1:08
The android:name is
com.google.android.gms.version.
1:12
GMS stands for Google Mobile Services,
which is the legacy name for
1:22
Google Play Services.
1:26
The value is actually stored
in Google Play Services,
1:27
it's
@integer/google_player_services_version.
1:32
You'll notice here that it doesn't
show up and that's because we
1:38
haven't included Google Play Services in
our app yet and we need to do that next.
1:41
To do that, we just go ahead and
go to our build.dreidel file and
1:46
we're gonna need to add in a dependency
in the dependency section.
1:51
Use the compile statement and
the dependency
1:57
we want is com.google.android.gms and
2:02
it's play-services-plus and
then the version that we want.
2:06
Every time that we change
our build.dreidel,
2:14
it's gonna ask us to reimport.
2:17
So we're going to go ahead and
just click Sync Now.
2:19
Once it syncs, you can see that the
version now shows up in our metadata tag
2:23
and all we need to do is complete this by
closing our tag and that's properly done.
2:27
Finally, we need to add in a few
permissions that are required by Google
2:32
play Services.
2:35
The three permissions we need
are Internet, GET_ACCOUNTS and
2:37
USE_CREDENTIALS.
2:41
Let's go ahead and add those in here.
2:42
If you just start typing
in the one you want,
2:45
it will fuzzy find in
the list of permissions.
2:47
The next is GET_ACCOUNTS.
2:53
And finally, USE_CREDENTIALS.
2:57
Great.
3:05
Now that we've done this, just go ahead
and make sure everything is good.
3:05
I'm just gonna click sync all,
make sure our app syncs with gradle,
3:09
everything will build right.
3:12
When dependent on Google Play Services,
we need to keep in mind that not
3:14
every Android device will
have access to these APIs.
3:18
Your app should handle this gracefully.
3:20
So here's what the app's gonna look
like when we're building it with
3:23
Google Play Services.
3:25
With Google Play services,
a user can plus one the listings and
3:26
that'll recommend those
listings to their friends or
3:30
they can possibly share it
using Google Plus directly.
3:33
Here's what our app looks like when
Google Play Services are not available.
3:37
You'll notice that the plus one is gone
now, but the Share button remains.
3:40
Instead of directly
sharing to Google Plus,
3:44
we'll provide a fall back mechanism
to the default share menu.
3:46
Later on, we'll walk through the steps
needed to make sure we know how to handle
3:50
this situation.
3:54
Great.
3:55
We've got all the pieces in
place to start building our app.
3:55
Before we move on though,
3:59
let's run the app to make sure
everything is in working order.
4:00
If you have any errors building, rewind
and make sure you didn't skip any steps.
4:04
Let's take a break.
4:09
And in the next stage,
4:10
we can write some code to display
the listings from the Etsy API.
4:11
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up