如何检查在Android的HDMI设备连接状态?状态、设备、Android、HDMI

2023-09-04 11:56:28 作者:温柔养猫人

我需要检测是否HDMI设备是否连接到Android设备。 对于这个我用一个BroadcastReceiver,它能够同时检测。 但随着BroadcastReceiver的我是无法处理的时候,我的申请被launced甚至在HDMI设备连接方案。在这种情况下的BroadcastReceiver无法找到如有HDMI设备连接或没有。 有没有什么办法可以知道,如果任何HDMI设备连接或根本没有任何意义呢?

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 BroadcastReceiver I'm unable to handle the scenario when the HDMI device is connected even before my application was launced. In this case the BroadcastReceiver is unable to find if any HDMI device is connected or not. Is there any way I can get to know if any HDMI device is connected or not at any point?

推荐答案

获得从位置数据文件/sys/class/display/display0.hdmi/connect.If在文件中的数据是0 HDMI如果没有连接其1其connected.Try此方法。

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

           }