1.布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.media.tv.TvView
android:id="@+id/tv_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
2.主界面代码
TvInputManager tvInputManager = (TvInputManager) getSystemService(TV_INPUT_SERVICE);
List<TvInputInfo> list = tvInputManager.getTvInputList();
TvView mTvView = findViewById(R.id.tv_view);
mTvView.reset();
Uri uri = buildChannelUriForPassthroughInput(list.get(0).getId());
new Handler().postDelayed(() -> mTvView.tune(list.get(0).getId(),uri),1000);
功能其实很简单, mTvView.tune(list.get(0).getId(),uri) 这一句需要延迟一点,可能跟加载uri速度有关系,不延迟的话显示不了.