问题
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