Use libCEC + USB dongle in Android app

天涯浪子 提交于 2019-12-07 01:15:32

问题


My goal is to send HDMI CEC commands from a standard (i.e non-system) app running on an Android box equipped with Pulse-Eight's USB dongle.

Following these instructions I successfully managed to compile libcec for Android and execute it as root on the box, with this command:

echo <my-cec-command> | cec-client -s /dev/ttyACM0

where /dev/ttyACM0 is the device file created by the system when plugging the dongle.

However the permissions of this file prevent the command to be executed by a non-root user (therefore it cannot be executed from my Android app).

On the other hand the app can actually access the USB dongle via the USB Host API of the Android SDK (provided the user grants the permission) and can even be wrapped into a USB serial controller with UsbSerial library.

But I don't see any way to make the bridge between the connection provided by Android's USB Host API and libcec/cec-client. Do you have any idea or suggestion?


回答1:


The best solution that I have found so far is to use USB Host API + UsbSerial library to read/write CEC packets on the adapter's serial port with pure Java code (no embedded libCEC).

I did some retro-engineering on libCEC to find out the appropriate commands for basic operations like switching TV on & off and setting active source.

And I finally came up with the following UsbCecConnection java class: https://gist.github.com/sdabet/ac4d7711d1a529806cb7b695530b1fac



来源:https://stackoverflow.com/questions/45639210/use-libcec-usb-dongle-in-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!