All right, so now that we have the Bluetooth components pretty much, we went pretty much went over it. Now we'll be going over the receiver and the remote aspect of the code. So if we look into my screen, we actually start off in the Main Activity. And the reason why we are explaining main activities is because the bluetooth receivers slash remote is actually just one application. And it depends on what fragment you choose to launch. So right now if you see on my code I have the receiver aspect of the code commented out. So what this will do is, if we port the application onto a phone, then it'll load up the remote side of it. Now, if we switch this and comment the remote aspect, then what we will be porting over would be the receiver. >> It's probably pretty important. >> Yeah, probably pretty important, cuz you wouldn't want to have two receivers that are just listening to each other and no one's talking. And you don't want two remotes talking to each other. Or you don't want two remotes not listening to each other. >> [LAUGH] >> So let's first go off with the receiver. So the receiver and the remote are pretty much the same thing. Pretty much the same code except for certain parts of it. So, let's just go over this. Cool. So, we have this fragment here that, when we create it, we just instantiate the BluetoothAdapter. So the fragments both receiver and remote, as it says here, we'll just control the bluetooth, and determine or relay the information to the bluetooth manager to begin to communicate with the other devices. So we have the on-create and we have these different on methods that will fire off depending on the state of the fragment. So if, on the startup of the application we're actually gonna try to set up the connection, and if the Bluetooth isn't turned off, or if the Bluetooth is turned off then you're gonna request it to be turned on. [COUGH] Let’s see. This on resume is actually pretty important. So, on resume is important especially for the receiver because of this specific line here, btManager.listen(); so the blue tooth manager, the one that we went over a couple videos ago, has this listen method. And for the bluetooth manager to know when to begin listening for connections, it's done in this onResume method. So the reason why I defined this method here is so that. Whenever you resume the fragment or the application, this gets immediately called and so your application is continuously listening. We have this onViewCreated. Now what this methods will do is it'll populate the screen with the specific layout. And onViewCreated will actually attach this receivedMessages so that when we press a button on the remote, the message is received and it'll show up on the screen. [COUGH] Setup connection is just a fancy way of saying we're going to instantiate the bluetooth manager so recall that the bluetooth manager is what is in charge of making the connection happen between the remote and the receiver. We also have on the bottom just some different UI related aspects, so setting the status to different aspects. We also have this handler here that will be used to pull information from the bluetooth manager and accordingly adjust the UI for the application. And we also have this on activity result which that will determine which course of action to take depending on what happened. So if you don't have bluetooth on and the application asks you to turn the bluetooth on, then this section of code here will fire and then it'll set up the connection. We also, oh sorry, forgot about this. So we also have this connect device method, that will use the bluetooth manager to connect to the specific device. So for the bluetooth manager to know which to connect to, it needs to know what the device name is. Which is what the bluetooth adaptor will pass onto this method. And that pretty much would sums up the receiver aspect of the code, so the remote fragment, or the remote part, is the same thing. The only main difference is on the view, on view created. So, as you can see, same exact code. The only difference is here. Instead of just attaching the received messages, we actually have to set the OnClickListeners for the different buttons. We have the yellow_on, red_on, green_on. The different buttons here were just setting the different listeners first, so when you press on it, it will call this method here, sendMessage. So the sendMessage method is, I believe, down here. So the sendMessage method will delegate to the bluetooth manager to write the message that you delegate it to now this will catch any errors, or this will ensure that you don't write out or you don't send a message randomly to cause your application to crash because of this check method here. So this will send whichever message you delegate to the receiver. Now, one thing to know is that for your application and your Gpio input parser to work you need to be able to consistently manage what messages are sent. So if we go back to onViewCreated we see that I send specific code here. I sent specific strings, and looking at our input parser, we actually send very similar code. There's very similar strings here too. So, make sure that you remain consistent with what you're sending so that your receiver and remote can tallk to each other properly. Now that pretty much sums up the bluetooth remote and the bluetooth receiver, so stay tuned and in the next video will show you how everything is tied together and show you the demo.