Step 2: Set Up TvInputService
Now it's time to set up the TvInputService
, which represents your streaming media source. It also allows you to provide parental controls, program guide information, and content ratings. Keep in mind that all the code on this page must be implemented before it will 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 Source
- Troubleshooting
- Next Steps
Create Minimal TvInputService
Create an Android Service class that extends TvInputService
.
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 > LiveTV > Sync Source > <input name> |
Declare Your TV Input Service in the Manifest
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, a SetupActivity
class (call it whatever you want) needs to be added. 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
}
}
The SetupActivity
should be created as a class as well as in the AndroidManifest XML file (see below).
Create the rich_setup XML file and define your layout there. 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>
Example of SetupActivity
in the AndroidManifest:
<activity android:name=".SetupActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
Checkpoint - Your Input Name Appears Under Sync Source
Do the steps below to verify that you have done everything correctly to this point:
- Build and install your APK onto Fire TV.
- Instructions to connect to ADB.
- How to install and run your app on ADB.
- Or this can be done through Android Studio. See image below.
- Navigate to Settings > Live TV > Sync Sources.
- Your input name should appear under the menu.
- Click on your name in the menu.
SetupActivity
should be launched.
If running and installing from Android Studio, an option for Fire TV should appear in the devices section.
Troubleshooting
The application is not showing up in Sync Sources
Get the device log:
adb logcat | grep "LiveTvSettings\|TIFUtils"
adb logcat | findstr "LiveTvSettings/|TIFUtils"
If you see something like:
TIFUtils: <your application> is not a configurable input. Removing from input list
LiveTvSettings: TvInput(s) found: .... <which doesn't include your application>
Most likely, the TvInputService
has not been correctly defined
To resolve this, verify the following:
- Has the Fire TV device been updated to the latest software?
- Navigating to Settings > My Fire TV > About > Check for Updates. Click on this 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?
I’ve tried everything above, but it’s still not working
- Open a terminal and search the logs in the ProviderRegistry:
adb logcat | grep ProviderRegistry
adb logcat | findstr ProviderRegistry
- On your Fire TV:
- Go to Settings > My Account > Sync Amazon Content.
- After a few seconds you should see logs like this:
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 be the same as what you submitted to be on the allow list. Reach out to your Amazon contact to have your debug package name and production package name added to the allow list.
Next Steps
Go to the next step: Step 3: Insert Your First Channel.
Last updated: Aug 12, 2022