Hello,
I want to build a companion app, which runs an HTTP api service and establishes an BLE connection when an NFC tag is scanned.
Afterwards, when an api request is received and a BLE connection is established, forward the command to the BLE device.
The purpose of the app is to run as a service only, without requiring user interaction, besides the NFC tag tapping.
So far I have a B4XPages project with a B4XMainPage, Starter service, a foreground service and a StartAtBootReceiver.
When an NFC tag is tapped, android starts the application, B4XMainPage appears and it tries to establish a BLE connection.
However, what I've made so far isn't entirely ideal.
The communication between the main page and the ble service is a bit awkward. I have a BleHelper class which is a public field in BleService.
The main page uses the Appear/Disappear events to register a callback.
Then from BleHelper I have the sub RaiseUpdatedEvent to raise connected/disconnected events.
Is there a better way to communicate between the service and the main page?
Is it a good idea to use B4XPages? Is the Starter service needed?
Is it possible to avoid having the application/activity appear and only have the foreground notification?
Any advice would be greatly appreciated.
I want to build a companion app, which runs an HTTP api service and establishes an BLE connection when an NFC tag is scanned.
Afterwards, when an api request is received and a BLE connection is established, forward the command to the BLE device.
The purpose of the app is to run as a service only, without requiring user interaction, besides the NFC tag tapping.
So far I have a B4XPages project with a B4XMainPage, Starter service, a foreground service and a StartAtBootReceiver.
When an NFC tag is tapped, android starts the application, B4XMainPage appears and it tries to establish a BLE connection.
However, what I've made so far isn't entirely ideal.
The communication between the main page and the ble service is a bit awkward. I have a BleHelper class which is a public field in BleService.
The main page uses the Appear/Disappear events to register a callback.
B4XMainPage:
Private Sub B4XPage_Appear
If Not(IsPaused(BleService)) Then
BleService.Ble.SetCallback(Me)
End If
End Sub
Private Sub B4XPage_Disappear
BleService.Ble.SetCallback(Null)
End Sub
Then from BleHelper I have the sub RaiseUpdatedEvent to raise connected/disconnected events.
BleHelper:
Private Sub RaiseUpdatedEvent
If CallbackTarget <> Null Then
CallSub(CallbackTarget, "Ble_StatusUpdated")
End If
CallSub(BleService, "Ble_StatusUpdated")
End Sub
Is there a better way to communicate between the service and the main page?
Is it a good idea to use B4XPages? Is the Starter service needed?
Is it possible to avoid having the application/activity appear and only have the foreground notification?
Any advice would be greatly appreciated.