mirror of
https://github.com/markqvist/Sideband.git
synced 2025-11-29 11:46:51 -05:00
Use local version of able
This commit is contained in:
parent
2e44d49d6b
commit
9b6a51a03e
67 changed files with 5305 additions and 0 deletions
56
libs/able/examples/service_advertise/main.py
Normal file
56
libs/able/examples/service_advertise/main.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
"""Start advertising service."""
|
||||
from able import BluetoothDispatcher, Permission, require_bluetooth_enabled
|
||||
from jnius import autoclass
|
||||
from kivy.app import App
|
||||
from kivy.lang import Builder
|
||||
|
||||
|
||||
kv = """
|
||||
BoxLayout:
|
||||
Button:
|
||||
text: 'Start service'
|
||||
on_press: app.ble_dispatcher.start_service()
|
||||
Button:
|
||||
text: 'Stop service'
|
||||
on_press: app.ble_dispatcher.stop_service()
|
||||
"""
|
||||
|
||||
|
||||
class Dispatcher(BluetoothDispatcher):
|
||||
@property
|
||||
def service(self):
|
||||
return autoclass("test.able.advservice.ServiceAble")
|
||||
|
||||
@property
|
||||
def activity(self):
|
||||
return autoclass("org.kivy.android.PythonActivity").mActivity
|
||||
|
||||
# Need to turn on the adapter, before service is started
|
||||
@require_bluetooth_enabled
|
||||
def start_service(self):
|
||||
self.service.start(
|
||||
self.activity,
|
||||
# Pass UUID to advertise
|
||||
"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
|
||||
)
|
||||
App.get_running_app().stop() # Can close the app, service will continue running
|
||||
|
||||
def stop_service(self):
|
||||
self.service.stop(self.activity)
|
||||
|
||||
|
||||
class ServiceApp(App):
|
||||
def build(self):
|
||||
self.ble_dispatcher = Dispatcher(
|
||||
# This app does not use device scanning,
|
||||
# so the list of required permissions can be reduced
|
||||
runtime_permissions=[
|
||||
Permission.BLUETOOTH_CONNECT,
|
||||
Permission.BLUETOOTH_ADVERTISE,
|
||||
]
|
||||
)
|
||||
return Builder.load_string(kv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ServiceApp().run()
|
||||
Loading…
Add table
Add a link
Reference in a new issue