In this article I’ll be showing you the steps I took to signal the mirror when Alexa starts and stops listening. Well, actually, I’m not alerting the mirror just yet, I’m sending a message to the debug hub.
In my last post I showed you how I was able to make a connection from the Java client to the debug hub using HTTP. That’s great, but it was a quick and dirty solution. We’re going to make this a bit more robust. I’ll start by adding a new class the the com.amazon.alexa.avs package, and call it “MirrorInterface“. You can see it near the bottom of the screenshot:
The content is pretty simple. I’ll be using the code to send the message and encapsulate it into a private method like so :
Notice how I already added support for both a command and extra content. For now I’ll be focussing on only a command. Also, the URL is added hardcoded too. I plan on reading this from a config file, but that’s only a “nice to have” right now.
I intentionally made it private as the public methods all refer to this one. I created a few, each serving their own purpose :
Notice the “VoiceActivated” and “VoiceDeactivated” methods. I’ll be incorporating them in the code of the Java Client. If you look in the “AVSController” java file you will see the following method overrides : “recordingStarted” and “recordingEnded”. They get called whenever Alexa starts to listen, and stops listening. That’s where I’ll be adding my code :
And that’s it. I issue a question to Alexa, and voila, the result in the debug hub.