【问题标题】:Kivy and discovering devices with bluetoothKivy 和使用蓝牙发现设备
【发布时间】:2014-10-11 17:04:55
【问题描述】:

我在这里看到 (https://gist.github.com/tito/7432757) 如何使用 pyjnius 访问 java 类,使用 kivy 通过蓝牙连接。我要做的是发现新设备并使用 sdp 不安全地连接到它们。我不确定如何在 kivy 中接收startDiscovery() 的结果。在java中你必须使用广播接收器。我是否也必须使用 pyjnius 从 android 访问广播接收器?

【问题讨论】:

    标签: android bluetooth kivy


    【解决方案1】:

    您错过了 Python-for-android / android.broadcast 模块中的 BroadcastReceiver :) 它完全满足您的需求,它是 Java / Pyjnius 中的一个实现,允许您在 Python 中接收结果。

    注意,你需要监听的动作需要用小写字母书写,不带ACTION_前缀。

    您的应用程序的模型可能如下所示:

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

    【讨论】:

    • 答案中的链接不再存在。
    猜你喜欢
    • 1970-01-01
    • 2012-04-19
    • 2017-03-17
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多