1 00:00:00,560 --> 00:00:05,221 Now let's finish the setup by adding in the final pieces to our Android 2 00:00:05,221 --> 00:00:06,413 studio project. 3 00:00:06,413 --> 00:00:09,656 Google has a code library to access Google play services, 4 00:00:09,656 --> 00:00:13,307 which we'll add with a small change to our build.dreidel file. 5 00:00:14,320 --> 00:00:18,169 We'll also need to add some permissions to the Android manifest. 6 00:00:18,169 --> 00:00:20,719 First, we need to ensure the code libraries for 7 00:00:20,719 --> 00:00:23,860 Google Play Services are downloaded and up to date. 8 00:00:23,860 --> 00:00:30,570 We can do this by opening the SDK Manager and scrolling down to the extra section. 9 00:00:30,570 --> 00:00:34,360 Ensure the Google Repository, Google Play Services, 10 00:00:34,360 --> 00:00:40,080 Android Support Library and Android Support Repository are all up to date. 11 00:00:40,080 --> 00:00:43,012 If updates are available, go ahead and download them now. 12 00:00:43,012 --> 00:00:45,892 Everything is up to date, so let's close this window and 13 00:00:45,892 --> 00:00:47,452 head to the Android manifest. 14 00:00:47,452 --> 00:00:49,860 We need to add in a metadata tag. 15 00:00:49,860 --> 00:00:54,240 This tag will store the version of Google Play Services where building our app with. 16 00:00:54,240 --> 00:00:58,318 Google Play Services will check this value when the app requests an API and 17 00:00:58,318 --> 00:01:02,739 if the Google Play Services on the device matches the number, it will proceed. 18 00:01:02,739 --> 00:01:04,778 If it doesn't match and needs updating, 19 00:01:04,778 --> 00:01:08,080 it'll prompt the user to update through Play Store. 20 00:01:08,080 --> 00:01:12,979 We just added as a metadata tag within our application. 21 00:01:12,979 --> 00:01:22,289 The android:name is com.google.android.gms.version. 22 00:01:22,289 --> 00:01:26,450 GMS stands for Google Mobile Services, which is the legacy name for 23 00:01:26,450 --> 00:01:27,910 Google Play Services. 24 00:01:27,910 --> 00:01:32,840 The value is actually stored in Google Play Services, 25 00:01:32,840 --> 00:01:38,330 it's @integer/google_player_services_version. 26 00:01:38,330 --> 00:01:41,846 You'll notice here that it doesn't show up and that's because we 27 00:01:41,846 --> 00:01:46,139 haven't included Google Play Services in our app yet and we need to do that next. 28 00:01:46,139 --> 00:01:51,539 To do that, we just go ahead and go to our build.dreidel file and 29 00:01:51,539 --> 00:01:57,246 we're gonna need to add in a dependency in the dependency section. 30 00:01:57,246 --> 00:02:02,065 Use the compile statement and the dependency 31 00:02:02,065 --> 00:02:06,632 we want is com.google.android.gms and 32 00:02:06,632 --> 00:02:13,500 it's play-services-plus and then the version that we want. 33 00:02:14,960 --> 00:02:17,544 Every time that we change our build.dreidel, 34 00:02:17,544 --> 00:02:19,294 it's gonna ask us to reimport. 35 00:02:19,294 --> 00:02:21,520 So we're going to go ahead and just click Sync Now. 36 00:02:23,300 --> 00:02:27,499 Once it syncs, you can see that the version now shows up in our metadata tag 37 00:02:27,499 --> 00:02:32,197 and all we need to do is complete this by closing our tag and that's properly done. 38 00:02:32,197 --> 00:02:35,842 Finally, we need to add in a few permissions that are required by Google 39 00:02:35,842 --> 00:02:37,570 play Services. 40 00:02:37,570 --> 00:02:41,138 The three permissions we need are Internet, GET_ACCOUNTS and 41 00:02:41,138 --> 00:02:42,334 USE_CREDENTIALS. 42 00:02:42,334 --> 00:02:45,066 Let's go ahead and add those in here. 43 00:02:45,066 --> 00:02:47,471 If you just start typing in the one you want, 44 00:02:47,471 --> 00:02:50,010 it will fuzzy find in the list of permissions. 45 00:02:53,660 --> 00:02:57,681 The next is GET_ACCOUNTS. 46 00:02:57,681 --> 00:03:05,084 And finally, USE_CREDENTIALS. 47 00:03:05,084 --> 00:03:05,681 Great. 48 00:03:05,681 --> 00:03:09,060 Now that we've done this, just go ahead and make sure everything is good. 49 00:03:09,060 --> 00:03:12,670 I'm just gonna click sync all, make sure our app syncs with gradle, 50 00:03:12,670 --> 00:03:14,930 everything will build right. 51 00:03:14,930 --> 00:03:18,004 When dependent on Google Play Services, we need to keep in mind that not 52 00:03:18,004 --> 00:03:20,321 every Android device will have access to these APIs. 53 00:03:20,321 --> 00:03:23,020 Your app should handle this gracefully. 54 00:03:23,020 --> 00:03:25,985 So here's what the app's gonna look like when we're building it with 55 00:03:25,985 --> 00:03:26,998 Google Play Services. 56 00:03:26,998 --> 00:03:30,708 With Google Play services, a user can plus one the listings and 57 00:03:30,708 --> 00:03:33,928 that'll recommend those listings to their friends or 58 00:03:33,928 --> 00:03:37,228 they can possibly share it using Google Plus directly. 59 00:03:37,228 --> 00:03:40,900 Here's what our app looks like when Google Play Services are not available. 60 00:03:40,900 --> 00:03:44,589 You'll notice that the plus one is gone now, but the Share button remains. 61 00:03:44,589 --> 00:03:46,653 Instead of directly sharing to Google Plus, 62 00:03:46,653 --> 00:03:50,130 we'll provide a fall back mechanism to the default share menu. 63 00:03:50,130 --> 00:03:54,184 Later on, we'll walk through the steps needed to make sure we know how to handle 64 00:03:54,184 --> 00:03:55,104 this situation. 65 00:03:55,104 --> 00:03:55,981 Great. 66 00:03:55,981 --> 00:03:59,413 We've got all the pieces in place to start building our app. 67 00:03:59,413 --> 00:04:00,667 Before we move on though, 68 00:04:00,667 --> 00:04:03,700 let's run the app to make sure everything is in working order. 69 00:04:04,760 --> 00:04:09,324 If you have any errors building, rewind and make sure you didn't skip any steps. 70 00:04:09,324 --> 00:04:10,604 Let's take a break. 71 00:04:10,604 --> 00:04:11,793 And in the next stage, 72 00:04:11,793 --> 00:04:15,180 we can write some code to display the listings from the Etsy API.