This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Nordic UART Service: Feed data to multiple Android Apps?

Is it possible to have the data from a Nordic UART Service (NUS) fed to multiple Apps (on the same Android device)?

  • You are best asking this on an Android forum. Sounds a bit hairy and as Android is notoriously inconsistent between versions and handsets with BLE I don't know why you would want to do this. Have you considered pulling data in via one app and then using local storage to make it accessible by/or pushing it to the other apps?

  • Yes, probably. Any recommendations for a "good" one?

    Reason to want it: there are various apps that can work with my BLE device. For testing, it could be convenient to have them all running on one Android device at the same time.

  • Hi, Yes, it's possible.

    What you have to do is:

    1. If the device is bonded, you may obtain list of bonded devices, select one you want (by address or name) and call device.connectGatt(..) to connect to it. It may already be connected by other apps, no problem. Then you just start using it normally as it you were the only app connected (enable notifications, start writing, ...).
    2. If the device is not bondable, you have to do a small trick. You have to open a GATT server in your application (doesn't have to have any services), and provide a BluetoothGattServerCallback instance. You will be immediately notified by onConnectionStateChange in this callback about ANY connected BLE device. Then just call device.connectGatt(...) and do as above.

    There is currently no other way on Android to obtain a list of connected devices (there is a method for that on iOS).

    After you are done with the device you have to disconnect it from all apps to terminate the physical connection.

    How to test it? You may use nRF Master Control Panel. In navigation menu select Configure GATT Server, select any configuration (can be the Sample one), go back, (make sure the 'Settings->Connectivity->Show incoming connection' option is set (default)), minimalize the nRF MCP app with a HOME button, or switch to your app (but don't close the MCP with a back button), connect to a device, start using it. Now, you may switch to nRF MCP and you'll see that it's connected. You may enable notifictions and you'll be getting the same data as your app.

    On Android N you may have both apps open at the same time using multiwindow :) (there is a but on Android N and you have to specify the Write type manually before writing a characteristic).

    Hope that helped, Aleksander

Related