我应该使用哪个模块来制作一个使用蓝牙的 Kivy 应用程序?

Which module should I use to make a Kivy application using bluetooth?

我想在 python kivy 中使用蓝牙创建游戏,但我不知道是否可行。我应该使用哪些模块来创建可以使用蓝牙的 kivy 应用程序

由于您尝试在 Android 上使用蓝牙制作游戏 Java class,您应该使用 Pyjnius 模块,它可以让 python 应用程序使用 java classes.

Pyjnius

的文档

你可以像这样使用 Pyjnius:

from jnius import autoclass

BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')
BluetoothSocket = autoclass('android.bluetooth.BluetoothSocket')
UUID = autoclass('java.util.UUID')

def get_socket_stream(name):
    paired_devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()
    socket = None
    for device in paired_devices:
        if device.getName() == name:
            socket = device.createRfcommSocketToServiceRecord(
                UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
            recv_stream = socket.getInputStream()
            send_stream = socket.getOutputStream()
            break
    socket.connect()
    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()