1

HDMI CEC on android

Hello in regard of the above post I have some questions Please first go through the above mentioned link. Reflection has been used to access the HDMI cec apis in android I want to send power ON/OFF command through android tv which has been installed on Raspberry pie and a TV is connected to the raspberry pie through HDMI I want to send simple power ON/OFF command to the target device(i.e TV)

 fun PowerOFFTargetTv(context: Context){
        try {
            val hdmiDeviceInfoClass =
                Class.forName("android.hardware.hdmi.HdmiDeviceInfo")

            val m: Method = context.javaClass.getMethod("getSystemService", String::class.java)
            val objHdmicontrolmanager: Any = m.invoke(context, "hdmi_control" as Any)

            val objectDeviceBuilder = hdmiDeviceInfoClass.javaClass.getMethod("cecDeviceBuilder")
            val m_hdmiDeviceInfo = hdmiDeviceInfoClass.javaClass.getConstructor()
            val objDeviceInfo = m_hdmiDeviceInfo.newInstance();

            Log.d(
                "HdmiHelper",
                "obj " + objDeviceInfo +"|"+objDeviceInfo.javaClass
            )
            val m_PowerOffTargetTv: Method =
                objHdmicontrolmanager.javaClass.getMethod("powerOffRemoteDevice",hdmiDeviceInfoClass)

            m_PowerOffTargetTv.invoke(objHdmicontrolmanager, objDeviceInfo)
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

This is the Function I have written which will be called for sending the Say Power OFF command https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/hdmi/HdmiDeviceInfo.java -> link for the HDMI device info class

Can anyone help me in this, how to make an instance of HdmiDeviceInfo in my case using reflection and so that it can be sent as a param using reflection in the powerOffDevice method of HdmiControlManager Class of android

0 Answers0