In this video it shows the steps to fetch the list of input IDs of Channels of your Android TV. It uses TvInputInfo object which it fetches from TvInputManager class.
TvInputInfo can also be used to get other items such as package, service info, etc.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
package com.programmerworld.inputidsofandroidtvchannels;
import androidx.appcompat.app.AppCompatActivity;
import android.media.tv.TvInputInfo;
import android.media.tv.TvInputManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
}
public void buttonShowInputIDs(View view){
TvInputManager tvInputManager = (TvInputManager) getSystemService(TV_INPUT_SERVICE);
List<TvInputInfo> tvInputInfoList = tvInputManager.getTvInputList();
StringBuilder stringBuilder = new StringBuilder("Size = " + String.valueOf(tvInputInfoList.size()));
for (TvInputInfo tvInputInfo: tvInputInfoList){
stringBuilder.append("\n" + tvInputInfo.getId());
}
textView.setText(stringBuilder.toString());
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.17"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.218" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="416dp"
android:layout_marginTop="16dp"
android:onClick="buttonShowInputIDs"
android:text="Show InputIDs"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshots:
Please note the above Input IDs are specific to TV brand and model number. So, it may give different results for each Android TV.
Excerpt:
The video demonstrates how to retrieve a list of input IDs from the channels on your Android TV using the TvInputInfo object from the TvInputManager class. In addition, the TvInputInfo object can retrieve package and service info. The source code for accomplishing all these is shared, showing how to import the necessary classes and specify a MainActivity. The video also highlights that the Input IDs vary based on the TV brand and model number. Any inquiries, suggestions, or appreciation can be addressed via the posted contact details.