Kivy and Bluetooth device discovery
I saw here ( https://gist.github.com/tito/7432757 ) how to use pyjnius to access java classes using kivy to connect via bluetooth. What I am trying to do is open new devices and connect to them insecurely using sdp. I'm not sure how to get the results startDiscovery()
in kivy. In java, you need to use a broadcast receiver. Should I use pyjnius to access the broadcast receiver from Android?
source to share
You missed the BroadcastReceiver in the Python-for-android / module android.broadcast
:) It does exactly what you need, it is an implementation in Java / Pyjnius that allows you to get the result in Python.
Note that the actions to be listened to must be written in lowercase, without a prefix ACTION_
.
The layout for your application might look like this:
class TestApp(App):
def build(self):
self.br = BroadcastReceiver(
self.on_broadcast, actions=['found'])
self.br.start()
def on_broadcast(self, context, intent):
# called when a device in found
pass
# Don't forget to stop and restart the receiver when the app is going
# to pause / resume mode
def on_pause(self):
self.br.stop()
return True
def on_resume(self):
self.br.start()
source to share