Hello, i have two projects in compose one for Wear...
# compose-wear
j
Hello, i have two projects in compose one for Wear and one for Mobile, i want to sync and share data between them, how can i perform it? Thanks in advance
y
Not really a compose question. But I'll offer some suggestions.
Sharing via the cloud, such as your server APIs, or firebase is good option for apps that should also work standalone
Second, the wearable data layer has message and data apis.
With the DataClient you can publish data like a Map and read from any connected devices. Generally 1 mobile, 1 or more watches
j
thanks , was already thinking in using firebase,
f
Hi! I have the exactly same use case and I was trying to use the DataClient API to send data from a smartwatch to a mobile phone. The Data seems to be sent from the smartwatch but the mobile app is not receiving any of the data events even though I have implemented the
onDataChanged
from
DataClient.OnDataChangedListener
, @yschimke Do you have any idea what could I be missing to be able to listen to the data events in the mobile app? I will appreciate any input or suggestion ☺️ Thank you in advance
j
Maybe take a look at a working sample like https://github.com/android/wear-os-samples/tree/main/DataLayer and see if you can work out from there
l
@Finlandia Make sure the manifest declaration is correct, that there's the receive boot completed permission, and that there's no crash in the code.
y
Are both apps running, or do you want them to wake up
If not running/subscribed, you'll need to use the WearableListenerService with filters.
f
Thank you all for replying. I appreciate it @John Nichol, I am using that code sample as reference and I am able to send data items from the mobile app to the wearable app (like in the DataLayer sample) but not the other way around (from the wearable app to the mobile app).
@louiscad and @yschimke: My android manifest in the mobile app looks like in the first image attached. The
DataLayerListenerService
class (also in the mobile app), which overrides the
onDataChanged
method can be seen in the second image. However, it seems the service is not listening to any the data changes triggered by the wearable app. am I missing something? Thanks for you help!
l
receive boot completed permission?
f
@louiscad sorry, what do you mean?
l
@Finlandia Did you Google it?
When it comes to permissions on Android and Wear OS, you want to look at
Manifest.permission
There, you can search for the keyword: "boot"
If your app doesn't have the permission to detect boot completed, it'll probably not have the permission to be started by external components like the Wear Data Layer until the app is opened by the user.
Also applies for push notifications (FCM) for example
f
Thank you for the clarification@louiscad . Yes, the mobile app has the receive boot completed permission . Also, I am able to send messages from the wearable app to mobile app using the message client. However, I can't send data from the wearable app to mobile app using the DataClient
l
Maybe you're targeting the wrong node?
Are you using
await()
or did you register a callback that also lets you know about failures for the message sending from the wear app?
y
Do both devices have internet connection?
The point by @louiscad also applies after force stopping the app, at least one report I've seen about this.
f
Yes, I am using
await()
as follows
dataClient.putDataItem(request).await()
. Both devices have internet connection and bluetooth connection enabled
Thanks for the link @yschimke. In the section highlighted in the image from the comparison table is stated "Send from one device to another device, such as from wear to mobile. Data Client: No, from the cloud to all the nodes", what does exactly mean? Does that mean that I can't send data from the wearable app to the mobile app with the dataclient?
y
I believe it means that even when the devices are directly connected, the data is shared via a cloud node. I suspect (but don't know for sure) it means that DataClient doesn't work with two paired devices but without internet connectivity.
It does mean that if you leave your mobile at home, your LTE watch can communicate using the DataClient./
f
I appreciate the explanation @yschimke. Then, to my understanding it should be possible to send data from the wearable to the mobile app with the data client. Unfortunately, the data client in my mobile app is still not capable of listening to the data items coming from the wearable app 😞
a
I believe you need to use the Channel Client to communicate directly from one node to another
y
Unless you need specifically byte streams, message client should be better suited than channels.
f
Thank you for replying! I need to share JSON objects (from mobile app to wearable) and CSV files (from wearable app to mobile )between the devices
l
@Finlandia You might want to try Protobuf with kotlinx.serialization instead so renaming properties doesn't break old data
y
A big +1 to proto
170 Views