Tag: 蓝牙sockets

消息没有收到蓝牙聊天。 我的处理程序是否坏了

我正在开发Android开发项目。 蓝牙的网站,它似乎是正确的发送消息,但没有收到他们。 过去,我试图创建另一个蓝牙应用程序,当连接到设备时,系统提示我确认连接,并显示PIN码。 在当前的应用程序工作时,我从来没有得到提示。 但是,它并没有出现任何exception情况,并且消息似乎正在发送。 这是我的Thread类用于管理连接: inner class ConnectedThread(val socket:BluetoothSocket, val socketType:String) : Thread(){ val inStream = socket.inputStream val outStream = socket.outputStream init { mState = STATE_CONNECTED } override fun run() { Log.i(TAG, “BEGIN mConnectedThread”) val buffer = ByteArray(1024) var bytes:Int while (mState == STATE_CONNECTED){ try { bytes = inStream.read(buffer) mHandler.obtainMessage(Constants.MESSAGE_READ, bytes, -1, buffer) .sendToTarget() […]

Kotlin readBytes()永远不会完成

我只是试图通过蓝牙套接字来读写,但是我的readBytes调用没有完成。 我认为这是非常简单的,但也许我只是使用错误types的流或东西。 截至目前我的代码只是发送少量的文字作为字节。 这是占位符代码,将被替换为通过流写入和读取文件的代码。 这是我的接收线程: class ReceiveThread(val inStream:BufferedInputStream):Thread() { var bytes:ByteArray? = null override fun run() { BluetoothService.log(“Begin ${BTS_Constants.THREAD_RECEIVE}”) BluetoothService.log(“preparing to read data”) name = BTS_Constants.THREAD_RECEIVE //here is my new code inStream.use { do{ count++ BluetoothService.log(“read loop round $count”) byteList.add(it.read() as Byte) }while (it.available()>0) } BluetoothService.log(“data read: ${byteList.get(0) as Char}”) } } 这是我的发送主题: class SendThread(val […]