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?
Asked
Active
Viewed 4,796 times
1 Answers
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
-
I think it depends on the device, I don't see a /sys/class/display on my device. – Andi Jay Mar 25 '14 at 13:55
-
yes,it depends on the manufactures but most of the devices will have this files. – Aj_31 Mar 26 '14 at 04:44