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();
}