общаться. Останавливается на BT 3
CoroutineScope(Dispatchers.IO).launch {
try {
Log.i("JCD", "BT CREATING")
// val btSocket = device.createRfcommSocketToServiceRecord(UUID.fromString(FIXED_UUID))
val btSocket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString(FIXED_UUID))
Log.i("JCD", "BT CONNECTING")
btSocket.connect()
Log.i("JCD", "BT CONNECTED")
val out = btSocket.outputStream
Log.i("JCD", "BT 1")
val w = out.writer(Charsets.UTF_8)
w.write("HELLO BLUETOOTH")
val input = btSocket.inputStream
Log.i("JCD", "BT 2")
val r = input.reader(Charsets.UTF_8)
Log.i("JCD", "BT 3")
val text = r.readText()
Log.i("JCD", "TEXT $text")
printLineToUI("TEXT $text")
} catch (t: Throwable) {
Log.e("JCD", "BT FUCK", t)
}
}
Со стороны сервера: CoroutineScope(Dispatchers.IO).launch { try { while (true) { Log.i("JCD", "BT ACCEPT") val btSocket: BluetoothSocket = btServerSocket.accept() val r = btSocket.inputStream.reader(Charsets.UTF_8) val w = btSocket.outputStream.writer(Charsets.UTF_8) do { val text = "TEXT " + r.readText() printLineToUI(text) w.write(text) } while (text != "end") } } catch (t: Throwable) { Log.e("JCD", "BT FUCK", t) } }
Стикер
Ппц, конечно. Reader просто не работает, хз почему
Обсуждают сегодня