【发布时间】:2020-03-11 07:20:10
【问题描述】:
我想开发将数据发送到 nodemcu 的 android studio 应用程序,并且我想将数据接收到 android textview。 或使用蓝牙模块的相同功能。因为使用蓝牙模块,我可以使用 android 应用程序控制 led。但我不知道如何在 android 应用程序上接收它。 有人可以帮忙吗?
【问题讨论】:
标签: android bluetooth textview communication nodemcu
我想开发将数据发送到 nodemcu 的 android studio 应用程序,并且我想将数据接收到 android textview。 或使用蓝牙模块的相同功能。因为使用蓝牙模块,我可以使用 android 应用程序控制 led。但我不知道如何在 android 应用程序上接收它。 有人可以帮忙吗?
【问题讨论】:
标签: android bluetooth textview communication nodemcu
如果你想联系classic bluetooth,那么你需要做一些事情。
(假设您已经配对了设备,或者您可以直接通过设备的设置进行配对)
用BluetoothAdapter从BluetoothManager扫描设备
val bluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE)
val bluetoothAdapter = bluetoothManager.adapter
通过BluetoothAdapter.bondedDevices获取你想与之通信的设备
val bondedDevices = bluetoothAdapter.bondedDevices
val device = bondedDevices[any](bondedDevices 类型为 Set)
调用createRfcommSocketToServiceRecord()创建Socket连接
val socket = device.createRfcommSocketToServiceRecord()
在connect 套接字之后,您可以从该套接字发送/检索outputstream/inputstream,最后是disconnect 连接。
socket.connect()
...
your comminucation here with socket.inputstream()/socket.outputStream()
...
socket.disconnect()
【讨论】: