参考
https://blog.csdn.net/phpxiaoxu/article/details/126266161
https://www.jianshu.com/p/c7954ab212b6
https://blog.csdn.net/qq_29848853/article/details/130258387
模拟器
-
模拟器使用的是android studio自带的,真机的话需要root权限
-
通过cmd打开模拟器
emulator -avd EasyPort -writable-system -netdelay none -netspeed full -qemu -serial COM3
//EasyPort 为安卓模拟器名称,com3是虚拟串口
3.cmd命令使模拟器 rootadb root //获取root权限,出现restarting adbd as root表示有root权限 adb shell setenforce 0 adb shell cd devchmod 777 ttyS*
4.查看模拟器是否绑定端口
代码项目来源
https://github.com/licheedev/Android-SerialPort-API
注:我直接新建项目,复制的代码
最终效果
setup设置如下 ttys1
console页面
注:电脑模拟器按回车发送信息