Question

I am creating a app where videos are played in T.v by connecting the android device to T.v through HDMI cable.I want detect if T.V is turned off using the HDMI cable.I also tried a method mentioned in this link but its not working. How to check the HDMI device connection status in Android?

Was it helpful?

Solution

Get the data file from the location /sys/class/display/display0.hdmi/connect.If the data in the file is 0 hdmi is not connected if its 1 its connected.Try this method.

try {

File file = new File("/sys/class/display/display0.hdmi/connect")
InputStream in = new FileInputStream(file);
byte[] re = new byte[32768];
int read = 0;
while ( (read = in.read(re, 0, 32768)) != -1)
{
    String string="Empty";
    string = new String(re, 0, read);
    Log.v("String_whilecondition","string="+string);
    result = string;

}
  in.close(); 
    } 
    catch (IOException ex) 

     {

          ex.printStackTrace();

       }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top