Today in the whole project, the need to use serial communications on the Internet to read a lot of people's posts just a little bit of a clue.
First, the serial code is the use of Google's own API, the Java code in the Java/android_serialport_api directory, if you want to change the registration need to use JNI to regenerate so file, here I directly use the package name to simplify the work.
The structure of the Androidstudio is as follows:
So file:
Add Dependencies in Gradle:
So you can
Although SerialPort has an error, he can do it without him.
This allows you to use the serial communication
Using a serial port requires a phone or simulator with a corresponding port and then requires root access. Here I use the simulator to test the serial port.
Test serial port requires two software, COM debugging assistant, virtual serial port driver
First open the virtual serial port driver to add two serial ports
Then find the path to the SDK is generally C:\Users\ your computer \appdata\local\android\sdk\tools
Set the emulator to the serial port on the PC.
This allows you to open the emulator to see
Indicates that your Android virtual machine is already a COM1
Then turn on the COM debugging assistant, so that the configuration device can COM1 and COM2 serial communication directly
Code Download Content Https://codeload.github.com/jzt-Tesla/GoogleSerialPort/zip/master
Android Serial Communication