使用HDMI电缆让Android设备检测显示屏是否开启或关闭

4

我正在创建一个应用程序,通过HDMI电缆将Android设备连接到电视上播放视频。我想要检测使用HDMI电缆是否关闭了电视。我也尝试了在此链接中提到的方法,但它没有起作用。 如何检查Android中的HDMI设备连接状态?

1个回答

0
从位置/sys/class/display/display0.hdmi/connect获取数据文件。如果文件中的数据为0,则HDMI未连接;如果为1,则已连接。
尝试以下方法:
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();
}

我认为这取决于设备,我在我的设备上看不到/sys/class/display。 - Andi Jay
是的,这取决于制造商,但大多数设备都会有这些文件。 - Aj_31

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接