All right so now that we learned more about intents and what they do, let's go ahead and create an intent right now and start the Jacob activity and we're going to start coding. >> All right, let's dive right into the screen. So, as you can see, we are currently in our test location method. Now if our provider is enabled we would then pull the location. However, if it isn't, currently the only thing we're doing is telling the user that it's not working. So as opposed to just telling them that it's not on, why don't we kind of add some more robustness. So we're gonna go ahead and delete that. And instead, ask them if they want to turn their GPS on. So the way that you go about doing that with intents is you create an intent object, let's call it, lo:Intent, we're gonna instantiate it there and pass in Settings.ACTION_LOCATION_SOURCE_SETTINGS. >> As you notice, the Android SDK has some predefined intents for you already so rather than trying to create a specific one tailored to GPS. They already provide one for us. >> So, now what we're gonna do then, after we create this intent. Is we're gonna call in the startActivityForResult and we're gonna pass in the specific location intent. Yeah, and what we also need to add in for startActivityForResult is a specific code. So for us, we're going to call this code REQUEST_LOCATION. So currently, this REQUEST_LOCATION isn't defined, so we're going to go ahead on the top of the screen and define that variable. So private static final int REQUEST_LOCATION. And we're gonna give it the value zero. Now the value here is kind of arbitrary. And the only important aspect is knowing later that the code is equal to the request location. >> With that in mind, make sure that all your request codes are unique and not the same or else there will be some conflict. >> Yeah. Now, next we want to then move on to our WiFi connectivity. So as you recall, we had one method that simply toggled the WiFi and another that was supposed to be able to connect to specific networks. Now before we kind of do that we want to first copy this code over, and the reason why we do this is because for you to be able to initiate this new intent you want to make sure that your WiFi is off. So if WiFi is not enabled. Oh no, fine. We can just do it this way. [LAUGH] So if WiFi is enabled, as opposed to, or no, sorry. If WiFi is not enabled, we're gonna go ahead and create a new intent. So we're gonna call this wifiIntent = new Intent(), and then very similarly to the location, we're gonna do settings.action_wifisettings. We're also gonna start activity for result, pass in wifi intent, and we'll do request. So once more, this is a variable that you define yourself. So, private static final int, and we'll make this one equal to one. >> So for this section, I noticed that you kept this setText and stuff like that. Should we somehow modify that? >> Yeah, we should. So if Wi-Fi is already enabled and you click this connectWifiNetwork, let's have it say, your WiFi is already enable, alright and we don't need to print out the Mac address. And we will show you later to add that portion to connect the WiFi access. >> Most likely that is because you want to wait to see what happens with the activity. >> Yes, so we are going to go ahead with the Bluetooth. So as opposed to just simply saying your Bluetooth is off, let's ask the user if they wanna turn it on. So, similarly again, we do Intent. btIntent = new Intent. >> It's gonna be a BluetoothAdapter. >> And then we're gonna pass in BluetoothAdapter.ACTION_REQUEST_ENABLE. And here, we're also gonna call start for activity results, passing the intent, and then request BT for boat. So the things we're doing here, they all fall under very similar, they essentially do the same thing. And it seems really easy though. Just calling the start activity from result and so on and so forth. >> Yeah, it gets a bit more complicated later as you will see. So now we kind of have all of these aspects or we have essentially all of the intents. So we're gonna go ahead and go to our on activity results which will kind of handle all the more complicated parts. So, with your activity results we should create a switch case and each of these parameters are specific to whatever activity we use so, the switch case that we want to be testing is the request code. And if you recall, we have a couple different cases so we have the request location. Right, I'm just gonna define all the cases for now. We have a request WiFi, break and then we have request Bluetooth, right. Then we're going to add a break there as well. So when you're requesting for your location, what you want to do to test to see if your location is enabled is you want to do something very similar to what we did before in the test location app. So you want to create your LocationManager. Get system service. Context dot location service. And here, if your manager is provider enabled, you'd put in. >> GPS? >> GPS or manager dot is provider enabled network. Oops. Oh. Oops. Location manager. Forgot about that. .network provided. So if they are provided then you can set the text. Location size.set text your location is enabled. And if it's not, then you can go ahead and say, setText("Please try again"). >> Cool, all right, seems simple enough. >> Now we do something similar to the WiFi. But recall instead of LocationManager, we'll be using the WifiManager. So very similar to what we learned in the previous section, we're gonna create this Wi-Fi manager object get system service. Settings dot, oh wait not settings. >> It's gonna be contacts. >> Contacts yeah contacts.wifiservice >> And then if your WiFi dot is enabled. Then you can say >> I is enabled? >> Yeah. >> [LAUGH] >> Set text here wi-fi is enabled. Else wi-fi status, set text >> To please try again. And lastly for Bluetooth, Bluetooths a bit different. We have to check to see if your result code is equal to the activity >> Activity.result, okay. >> So what does that do, exactly? >> So what this is saying is that because, as opposed to opening the settings page, requesting for Bluetooth isn't through. As we can see in this intent, it's not, through the settings, it's through its own bluetooth adapter. It does a different kind of performance check. So, your result code will return either okay or one or false or incorrect for zero. So, we want to check to see if the activity resulted in the user saying yes. >> Got you. >> So for here we can do btStatus, that's setText to your bluetooth is enabled. And conversely if it's not, we can tell the user to try again. Please try again. And with that in mind, this kind of wraps up the onActivity result. As you can see, each button should now, when pressed will either check to see if it's already on, or if it's not on, ask the user if they wanna turn it on. And do note that when we give you the reviewed code it will be a bit more cleaner and we'll kind of explain the differences. So we'll see you there.