Step 2: Set Up TvInputService
Now it's time to set up the TvInputService
, which represents your streaming media source. With TV input service, you can provide parental controls, program guide information, and content ratings. Keep in mind that you must implement all code on this page before your app can compile and install correctly.
- Create minimal TvInputService
- Define input service's resource XML file
- Declare your TV input service in the manifest
- Define SetupActivity
- Checkpoint: Your input name appears under sync sources
- Troubleshooting
Create minimal TvInputService
Create an Android Service class that extends TvInputService
.
The following is an example of a minimal implementation of TvInputService
.
package com.example.android.sampletvinput; // replace with your package
import android.media.tv.TvInputService;
public class RichTvInputService extends TvInputService {
@Override
public Session onCreateSession(String inputId) {
return null;
}
}
package com.example.android.sampletvinput // replace with your package
import android.media.tv.TvInputService
class RichTvInputService : TvInputService() {
override fun onCreateSession(inputId: String): Session? {
return null
}
}
Define input service's resource XML file
Each input service must have a resource XML file which defines common input attributes. Here's an example of such a file, located in res/xml/richtvinputservice.xml
:
<?xml version="1.0" encoding="utf-8"?>
<tv-input xmlns:android="http://schemas.android.com/apk/res/android"
android:canRecord="true"
android:setupActivity="com.example.android.sampletvinput.SetupActivity" />
com.example.android.sampletvinput
.Important Details
Activity | Required? | Notes |
---|---|---|
android:setupActivity |
Yes | This will be launched when the user navigates to Settings > Live TV > Sync Source > <input name> |
Declare your TV input service in the manifest
The following is an example of TvInputService
in the application
section of AndroidManifest.xml.
<service
android:name=".RichTvInputService"
android:label="My Input Name"
android:permission="android.permission.BIND_TV_INPUT">
<!-- Required filter used by the system to launch our account service. -->
<intent-filter>
<action android:name="android.media.tv.TvInputService" />
</intent-filter>
<!--
An XML file which describes this input. This provides pointers to the
SetupActivity to the system/TV app.
-->
<meta-data
android:name="android.media.tv.input"
android:resource="@xml/richtvinputservice" />
</service>
Important details
Activity | Required? | Input | Notes |
---|---|---|---|
android:label |
Yes | "My Input Name" | Put your own service name here |
android:permission |
Yes | "android.permission.BIND_TV_INPUT" | This gives Android permission to allow the service to connect the TV input to the system. |
<intent-filter> | Yes | <action> | A filter used by the system to launch the service. |
android:name |
Yes | "android.media.tv.input" | It must be the correct name for Android to recognize the service correctly. The resource must point to the structured XML file defined below. |
Define SetupActivity
To add logic to the app, you must add a SetupActivity
class (you can choose the name of this class). The following is an example of a SetupActivity
class to invoke the activity.
import android.app.Activity;
import android.os.Bundle;
public class SetupActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rich_setup); // create rich_setup.xml
}
}
import android.app.Activity
import android.os.Bundle
import com.example.android.sampletvinput.R
class SetupActivity : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.rich_setup) // create rich_setup.xml
}
}
Create SetupActivity
as a class and add the activity in the Android manifest XML file, as shown in the following code.
<activity android:name=".SetupActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
Create a rich_setup XML file and define your layout there. The following is an example of rich_setup.xml inside the layout folder.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Checkpoint: Your input name appears under sync sources
Use the following steps to verify your setup.
- Build and install your APK on a Fire TV.
- Connect to Fire TV through ADB.
- Install and run your app.
- Alternatively, you can use Android Studio to install and run your app.
- Navigate to Settings > Live TV > Sync Sources.
- Your input name should appear under the menu.
- Click on your name in the menu.
The SetupActivity
should launch.
![What you should see if Android Studio connects to your device](https://m.media-amazon.com/images/G/01/mobile-apps/dex/firetv/ADB-Android_Studio._TTH_.png)
If running and installing from Android Studio, an option for Fire TV should appear in the devices section.
Troubleshooting
This section contains steps to troubleshoot issues you might encounter.
- The application is not showing up in sync sources.
-
Use the following command to get the device log.
Get the device log (Linux or Mac):adb logcat | grep "LiveTvSettings\|TIFUtils"
Get the device log (Windows)adb logcat | findstr "LiveTvSettings/|TIFUtils"
If you see a message similar to the following:
TIFUtils: <your application> is not a configurable input. Removing from input list LiveTvSettings: TvInput(s) found: .... <which doesn't include your application>
It's possible that the
TvInputService
has not been correctly defined.To resolve this, verify the following:
- Has the Fire TV device been updated to the latest software?
- Go to Settings > My Fire TV > About > Check for Updates. Select this option and update if needed.
- Does the InputService have correct permissions?
- Does the InputService have the correct intent-filter?
- Does the InputService have the correct meta-data defined?
- Does the InputService's meta-data link to the correct XML resource?
- Does the XML resource have the
SetupActivity
defined? Is theSetupActivity
valid?
- Has the Fire TV device been updated to the latest software?
- I've tried everything above, but it's still not working.
-
At the command prompt, search the logs for
ProviderRegistry
.ProviderRegistry logs (Linux or Mac):adb logcat | grep ProviderRegistry
ProviderRegistry logs (Windows)adb logcat | findstr ProviderRegistry
On your Fire TV, go to Settings > My Account > Sync Amazon Content. After a few seconds you should see logs similar to these.
08-06 17:09:05.684 694 757 I ProviderRegistry: No change for InstalledProvider(configuration=ProviderConfiguration(packageName=com.example.android.sampletvinput, logoId=1254252374292, rowId=null, defaultRank=1, defaultSortOrder=NONE, showBroadcastRatingsFlag=false, tvInputsSupported=false, qualifierId=, supportedContent=[LINEAR], eventRowId=null, featureBlacklist=[], userProviderPreference=UserProviderPreference(mProviderId=, mRank=2147483647, mSortOrder=NONE), stationCount=4)
If your app name doesn't appear in the log as an InstalledProvider, then it's not in the allow list properly. The package name should match what you submitted to be on the allow list. To have your debug package name and production package name added to the allow list, contact your Amazon representative.
Last updated: Feb 06, 2025