4

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?

Community
  • 1
  • 1
Nik
  • 111
  • 2
  • 8

1 Answers1

0

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();
}
Federico Perez
  • 976
  • 1
  • 13
  • 34
Aj_31
  • 187
  • 2
  • 6