Download the Alexa Client Library
You can download the Alexa Client Library here: Note that by downloading the Alexa Client Library, you agree to Amazon’s Program Materials License Agreement. For more details on versions, see the Alexa Client Library Release Notes.About the Alexa Client Library
The Alexa Client Library allows you to do the following:- Authenticates with Amazon using Login with Amazon (LWA) for Android.
- Automatically pairs your skill with an Echo device by inferring a relationship from an existing Echo to Fire TV (rather than requiring a customer to add the skill through the Alexa App).
- Manages application lifecycle events and sends those events back to Alexa (which will help Alexa make more intelligent decisions when users interact with voice-enabled Fire TV apps).
- Sends Alexa responses to directives received in your application.
Update the Alexa Client Library in your Fire TV App
To update an existing version of the Alexa Client Library in your Android Studio project:- Download the Alexa Client Library. After downloading the file, unzip it. The zip folder contains a file called
AlexaClientLib.aar. - In Android Studio, right-click the AlexaClientLib module and select Reveal in Finder (Mac) or Show in Explorer (Windows).
- Open the AlexaClientLib folder.
- Drag in the new
AlexaClientLib.aarfile, replacing the existing one. When asked if you want to overwrite the file, choose “Replace.”
Add the Alexa Client Library to your Fire TV App
To add the Alexa Client Library (AlexaClientLib.aar) into your Android Studio project, do the following:
- Download the Alexa Client Library from the link above. After downloading the file, unzip it. The zip contains a file called
AlexaClientLib.aarand some documentation. - In your Android Studio project, go to File > New > New Module.
- Select Import .JAR/.AAR Package and click Next.
- In the File name field, select the
AlexaClientLib.aarfile and click Open, and then click Finish. - Go to File > Project Structure.
- Under Modules in the left menu, select app.
- Go to Dependencies tab.
- If you don’t already see AlexaClientLib in the list of dependencies, click the + button in the bottom and select 3. Module dependency.
- Select the AlexaClientLib from the list.
Configure Proguard
If you’re using ProGuard in your Android project, make the following update:- Locate your proguard rules file.
-
Add the following configuration:
Initialize the Alexa Client Library from Your App’s onCreate
The Alexa Client Library must be initialized for the client library to work correctly. DeclareinitializeAlexaClientLibrary() in your Application class. Reference the following code sample. Make sure to call initializeAlexaClientLibrary() from onCreate().
General Notes
-
The skill stage is set to
SKILL_STAGE_DEVELOPMENT. Later in the development process, when you’re ready to publish your app (in Step 12: Go Live!), you will changeAlexaClientManager.SKILL_STAGE_DEVELOPMENTtoAlexaClientManager.SKILL_STAGE_LIVE. - If an event (for example, a visibility change, such as backgrounding/foregrounding the app) occurs before initialize is called, the app will not respond to voice until the app is force-stopped and restarted.
Declaring Capabilities
The previous sample code declares support for these capabilities:AlexaClientManager.CAPABILITY_CHANNEL_CONTROLLER, Alexa will send ChangeChannel directives when users say “Change the channel to PBS.” If you don’t have the capability declared, Alexa won’t send directives related to the capability. For more detail, see the Discover Directives.
If your app doesn’t support a particular capability, omit that capability. Additionally, you can add AlexaClientManager.CAPABILITY_RECORD_CONTROLLER and AlexaClientManager.CAPABILITY_KEYPAD_CONTROLLER if your app supports the functionality of these APIs. The capabilities are described in the following table.
| Alexa Client Library Capability | Directive Capability | Directives |
|---|---|---|
CAPABILITY_CHANNEL_CONTROLLER | Alexa.ChannelController | ChangeChannel |
CAPABILITY_REMOTE_VIDEO_PLAYER | Alexa.RemoteVideoPlayer | SearchAndDisplayResultsSearchAndPlay |
CAPABILITY_PLAY_BACK_CONTROLLER | Alexa.PlaybackController | PausePlayStopResumeNextPreviousFastForwardRewindStartOver |
CAPABILITY_SEEK_CONTROLLER | Alexa.SeekController | AdjustSeekPosition |
CAPABILITY_KEYPAD_CONTROLLER | Alexa.KeypadController | SendKeystroke |
List<String> capabilities) in the client library, you can do so by using the exact string name of that capability. For example, you would add the “Launcher” capability for GUI shortcuts as follows: capabilities.add(\"Alexa.Launcher\");.
Customize the Skill ID
In the previous code, replaceYOUR_SKILL_ID with your own Video Skill ID, which you copied earlier in Step 1: Create a Video Skill and Set Up Devices.
Enable or Disable the Alexa Client Library When User Sign In or Out
The functionsetAlexaEnabled() is used to enable or disable an app instance as a targetable endpoint by the user. It’s recommended that you enable Alexa (setting setAlexaEnabled(true)) only for subscribed customers. (Hence the inline comment in the code that says you can delay this step until the active user signs in to your application.) Do the following:
- Call
setAlexaEnabled(true)when the user logs into your app - Call
setAlexaEnabled(false)when the user logs out
Construct a Down-Channel Service
To receive directives from the Alexa Service, you must construct a down-channel service in your app as per the previous sample reference code. The down-channel is a stream primarily used to deliver cloud-initiated directives to your Fire TV app. Note the following about the down-channel service. When your down-channel service is ready, call thesetDownChannelReady() API with parameters as follows:
- The first parameter (
isDownChannelReady) should betrueto indicate that your down-channel is ready. - The second parameter (
appInstanceId) should be a string that uniquely identifies your application instance. If you are using Amazon Device Messaging (ADM), use the app’s ADM Registration ID for this parameter. (If you prefer not to use ADM, you can use another technology.)
setDownChannelReady() API each time with the proper status flag value.
Initialize the ADM service (initializeAdm();) at application creation time. The preceding code shows a sample ADM reference implementation.
Provide the application instance ID when your down channel is ready.

