not able to scan BLE around

24 views
Skip to first unread message

ycheva...@gmail.com

unread,
Mar 24, 2018, 10:40:04 AM3/24/18
to PyJNIus development ML
Hello

I'd like to scan BLE around. I'm using the code below (which I'm able to build with buildozer) but the applications crashes afterwards.
Any idea where the mistake comes from?

cheers!
__________________________

from jnius import autoclass
from jnius import PythonJavaClass, java_method
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

Hardware = autoclass('org.renpy.android.Hardware')
BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')
BluetoothSocket = autoclass('android.bluetooth.BluetoothSocket')
BluetoothGatt = autoclass('android.bluetooth.BluetoothGatt')
BluetoothGattCallback = autoclass('android.bluetooth.BluetoothGattCallback')
UUID = autoclass('java.util.UUID')
List = autoclass('java.util.List')
BluetoothGattService = autoclass('android.bluetooth.BluetoothGattService')
Intent = autoclass('android.content.Intent')
BluetoothProfile = autoclass('android.bluetooth.BluetoothProfile')
Service = autoclass('android.app.Service')
etatconnexion = 0

paired_devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()

PythonActivity = autoclass('org.renpy.android.PythonActivity')
activity = PythonActivity.mActivity
btManager = activity.getSystemService(Context.BLUETOOTH_SERVICE)
btAdapter = btManager.getAdapter()


class Hello(App):
    def build(self):
        layout = BoxLayout(orientation = "vertical")
        btn1 = Button(text = str(Hardware.getDPI()))
        btn2 = Button(text = str(len(paired_devices)))
        btn3 = Button(text = "Hello world")
        btn4 = Button(text = "Hello world")
        layout.add_widget(btn1)
        layout.add_widget(btn2)
        layout.add_widget(btn3)
        layout.add_widget(btn4)
        return layout

if __name__ == '__main__':
    Hello().run()  #start our app
Reply all
Reply to author
Forward
Message has been deleted
0 new messages