Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 发生JVM异常:需要蓝牙权限:用户10258和当前进程都没有android.permission.Bluetooth python jnius?_Java_Python_Bluetooth_Jvm_Kivy - Fatal编程技术网

Java 发生JVM异常:需要蓝牙权限:用户10258和当前进程都没有android.permission.Bluetooth python jnius?

Java 发生JVM异常:需要蓝牙权限:用户10258和当前进程都没有android.permission.Bluetooth python jnius?,java,python,bluetooth,jvm,kivy,Java,Python,Bluetooth,Jvm,Kivy,我想创建蓝牙应用程序,我有.apk文件,其中包含以下代码: 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): paired_devices = BluetoothAdapter.getDefaultAdapter().

我想创建蓝牙应用程序,我有
.apk
文件,其中包含以下代码:

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):
    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()

class ExampleApp(App):
    def build(self):
        global BluetoothAdapter, BluetoothDevice, BluetoothSocket, UUID
        self.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:
           self.fl.add_widget(Label(text=str(error), pos=(0, 0), font_size=(20)))
       return self.fl

if __name__ == '__main__':
    ExampleApp().run()
我得到一个错误:

JVM exception occured:Need Bluetooth permission: Neither user 10258 not current process has android.permission.Bluetooth

我怎样才能修好它?我没有找到如何在python中修复它的答案,希望您能帮助我当您缺少权限时,您必须将其添加到.p4a文件或通过命令行

--permission BLUETOOTH
会有帮助的。 也许你需要

--permission BLUETOOTH_ADMIN
还有

如果你使用buildozer,你必须添加

 android.permissions = BLUETOOTH_ADMIN,BLUETOOTH

在buildozer.spec

中,我创建了
main.p4a
文件并输入
--permission BLUETOOTH\u ADMIN'
,但我得到了相同的错误。我做错了什么?当你用python4android创建包时,只有“.p4a”。。。当您使用另一个软件包管理器创建时,请指定我创建的
.apk
文件和buildozer用我为buildozer找到的内容编辑我的答案