Using UART in Android


i want to use UART in Android but don’t know where i gonna make changes to enable it. can i enable it inside android or i must build it from scratch and make some changes there? is it possible to send command using android apks written in JAVA without need to android NDK?


What’s the version of your system? You can refer to the demo to control UART when your system is newer than VIM_Nougat_V170901.
Have a try, Thanks


I am using Vim_Nougat_Root_170612. I will try your demo as soon as possible.
There is another question: is it possible to control UART from android shell ? ( like Raspberry Pi )


It is possible to control UART from android shell. But you need to create a executable file for it with Program C.
You can hava a try . Thanks.


can you mention any tutorial for controlling UART using C program in Android?
Thanks a lot.


I couldn’t install the apk you provided.There was a conflict error.
even couldn’t build it using Android Studio.


I created this demo on eclipse and not studio. You can refer to those source code and create yourself project.


I created a project in Studio and successfully built it. now there is another problem: the problem is that I couldn’t receive anything from UART. is there another step to make it work, which i have missed?


Did you can open the UART device( /dev/ttyS4 )?

mFd = open(device.getAbsolutePath(), baudrate);
if (mFd == null) {
    Log.e(TAG, "native open returns null");
    throw new IOException();
mFileInputStream = new FileInputStream(mFd);
mFileOutputStream = new FileOutputStream(mFd);


There is no error log in Android studio logcat. It seems there is no problem opening UART device.


What’s the model did you connect Uart port with? How did you control UART with app demo?
You can try to connect UART_RX_AO_B to UART_TX_AO_B with Line.
Firstly, you need to click the ‘Open SerialPort’ button. Then click ‘Send Message’ button. Finally, You can see the ‘Hello’ message on EditText.
More about how to control Uart on Android app, You need to seach for it on google. :smile:


I could control UART using this app.
Thanks for your help terry