问题描述
我在这里看到过(https://gist.github.com/tito/7432757) 如何使用 pyjnius 访问 java 类,使用 kivy 通过蓝牙连接.我要做的是发现新设备并使用 sdp 不安全地连接到它们.我不确定如何在 kivy 中接收 startDiscovery() 的结果.在java中你必须使用广播接收器.我是否也必须使用 pyjnius 从 android 访问广播接收器?
I have seen here (https://gist.github.com/tito/7432757) how to use pyjnius to access the java classes using kivy to connect via bluetooth. What I am trying to do is to discover new devices and connect to them insecurely using sdp. I'm not sure how to receive the results of startDiscovery() in kivy. In java you have to use a broadcast receiver. Do I have to use the pyjnius to access the broadcast receiver from android as well?
推荐答案
你错过了 android.broadcast 模块中的 android.broadcast" rel="nofollow">BroadcastReceiver :) 它完全符合您的需要,它是 Java/Pyjnius 中的一个实现这允许您在 Python 中接收结果.
You've missed the BroadcastReceiver in the Python-for-android / android.broadcast module :) It does exactly what you need, it's an implementation in Java / Pyjnius that allows you to receive the result in Python.
注意,需要监听的动作需要小写,不带ACTION_前缀.
Note that the actions you need to listen need to be written in lowercase, without the ACTION_ prefix.
您的应用程序的模型可能如下所示:
A mockup for your application can 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()
这篇关于Kivy 和使用蓝牙发现设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)