如何检查在Android的HDMI设备连接状态? [英] How to check the HDMI device connection status in Android?

查看:633
本文介绍了如何检查在Android的HDMI设备连接状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测是否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();

           }

这篇关于如何检查在Android的HDMI设备连接状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆