I need to detect whether an HDMI device is connected or not to my Android device. For this I\'m using a BroadcastReceiver and it is able to detect also. But with BroadcastRe
You can get the data from /sys/class/display/display0.hdmi/connect. If the content of the file is 0, HDMI is not connected, otherwise if it's 1, HDMI is connected.
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 = new String(re, 0, read);
Log.v("String_whilecondition", "HDMI state = " + string);
result = string;
}
in.close();
} catch (IOException ex) {
ex.printStackTrace();
}