简体   繁体   English

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

[英]JVM exception occured:Need Bluetooth permission: Neither user 10258 not current process has android.permission.Bluetooth python jnius?

I want to create Bluetooth app, I have .apk file with this code:我想创建蓝牙应用程序,我有带有以下代码的.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()

And I get error:我得到错误:

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

How can I fix it?我该如何解决? I didn't find the answer how to fix it in python, I hope you help me.............................................................我没有找到如何在python中修复它的答案,希望你能帮助我...................................... ……………………………………………………………………………………………………………………………………………………………………………………

When you have missing permissions you have to add them in the .p4a file or via command line当您缺少权限时,您必须将它们添加到 .p4a 文件中或通过命令行

--permission BLUETOOTH

will help.会有所帮助。 Probably you need可能你需要

--permission BLUETOOTH_ADMIN

as well.以及。

If you use buildozer you have to add如果您使用 buildozer,则必须添加

 android.permissions = BLUETOOTH_ADMIN,BLUETOOTH

in buildozer.spec在 buildozer.spec 中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.SecurityException:需要 BLUETOOTH 权限:用户 10065 和当前进程都没有 android.permission.BLUETOOTH - java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10065 nor current process has android.permission.BLUETOOTH Android棒棒糖java.lang.SecurityException:用户和当前进程都没有android.permission.BLUETOOTH_PRIVILEGED - Android lollipop java.lang.SecurityException: Neither user nor current process has android.permission.BLUETOOTH_PRIVILEGED java.lang.SecurityException:UID 10457 / PID 24525 缺少权限 android.permission.BLUETOOTH - java.lang.SecurityException: UID 10457 / PID 24525 lacks permission android.permission.BLUETOOTH 用户10031和当前进程都没有android.permission.INSTALL_PACKAGES - Neither user 10031 nor current process has android.permission.INSTALL_PACKAGES java.lang.SecurityException:用户 11029 和当前进程都没有 android.permission.SET_TIME_ZONE - java.lang.SecurityException: Neither user 11029 nor current process has android.permission.SET_TIME_ZONE 正在获取java.lang.SecurityException:ConnectivityService:用户10062或当前进程都没有android.permission.ACCESS_NETWORK_STATE。” - Geting java.lang.SecurityException: ConnectivityService: Neither user 10062 nor current process has android.permission.ACCESS_NETWORK_STATE." 需要 BLUETOOTH 权限:我在某些意图 Android Studio 中没有权限 - Need BLUETOOTH permission : i don't have permission in some intent Android Studio Android Bluetooth_admin权限错误 - Android Bluetooth_admin permission error java.lang.SecurityException:需要 android.permission.BLUETOOTH_CONNECT 权限以获得 AttributionSource - java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for AttributionSource 在 android studio java.lang.SecurityException 中查找错误:需要 android.permission.BLUETOOTH_CONNECT - Finding Error in android studio java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM