Use the termux-api helper binary
masterThe termux-api client binary (provided in the termux-api package) acts as the bridge between the command line and the Android API. It uses Linux anonymous namespace sockets to communicate with the TermuxApiReceiver broadcast receiver.
Standard communication follows this pattern:
- The
termux-apibinary generates two sockets (input and output). - It passes these socket addresses to the Android system via an
am broadcastcommand. stdinis forwarded from the binary to the API class, and the API class's output is forwarded to the binary'sstdout.
/system/bin/am broadcast ${BROADCAST_RECEIVER} --es socket_input ${INPUT_SOCKET} --es socket_output ${OUTPUT_SOCKET}