У меня есть код:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from jnius import autoclass
from kivy.uix.label import Label
def get_socket_stream(name):
global fl
paired_devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()
socket = None
for device in paired_devices:
if device.getName() == name:
device.fetchUuidsWithSdp()
socket = device.createRfcommSocketToServiceRecord(
UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
recv_stream = socket.getInputStream()
send_stream = socket.getOutputStream()
break
socket.connect()
socket.close()
return recv_stream, send_stream
class Bluetooth():
def __init__(nameOfDevice):
self.recv_stream, self.send_stream = get_socket_stream(nameOfDevice)
def send(self, cmd):
self.send_stream.write('{}\n'.format(cmd))
self.send_stream.flush()
class ExampleApp(App):
def build(self):
global BluetoothAdapter, BluetoothDevice, BluetoothSocket, UUID, fl
fl = FloatLayout()
try:
BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')
BluetoothSocket = autoclass('android.bluetooth.BluetoothSocket')
UUID = autoclass('java.util.UUID')
get_socket_stream('DESKTOP-I2CNCPQ')
#self.fl.add_widget(Label(text='no errors', pos=(0, 0), font_size=(40)))
except Exception as error:
fl.add_widget(Label(text=str(error), pos=(0, 0), font_size=(20)))
return fl
if __name__ == '__main__':
ExampleApp().run()
, и я получаю сообщение об ошибке:
JVM exception occured: read failed, socket might closed or timeout, read ret:-1
Я не знаю, почему это происходит и как это исправить. Надеюсь, ты мне поможешь ............................................. .................................................. ..................