In this video it shows the steps to access the HDMI input in your Android App. It uses VideoView to show the content of the input channel by converting it to the respective uri.
For the complete list of input types, such as TYPE_DVI, TYPE_HDMI, or TYPE_VGA, please refer to: https://developer.android.com/reference/android/media/tv/TvInputInfo
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.hdmiinputforandroidtv;
import static android.media.AudioDeviceInfo.TYPE_HDMI;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.media.tv.TvContract;
import android.media.tv.TvInputInfo;
import android.media.tv.TvInputManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = findViewById(R.id.videoView);
}
public void buttonSetHDMIInput(View view){
TvInputManager tvInputManager = (TvInputManager) getSystemService(TV_INPUT_SERVICE);
TvInputInfo tvInputInfo = tvInputManager.getTvInputInfo(String.valueOf(TYPE_HDMI));
// Uri uriTVInput = TvContract.buildChannelUriForPassthroughInput(tvInputInfo.getId());
Uri uriTVInput = TvContract.buildChannelUriForPassthroughInput(String.valueOf(tvInputInfo));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(uriTVInput);
startActivity(intent);
videoView.setVideoURI(uriTVInput);
}
}
<?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">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="408dp"
android:layout_marginTop="44dp"
android:onClick="buttonSetHDMIInput"
android:text="Set HDMI Input"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<VideoView
android:id="@+id/videoView"
android:layout_width="732dp"
android:layout_height="370dp"
android:layout_marginStart="114dp"
android:layout_marginTop="41dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
</androidx.constraintlayout.widget.ConstraintLayout>
No HDMI input: