patloew / RxWear

⌚️ Reactive Wearable API Library for Android and RxJava
Other
158 stars 14 forks source link

Uri for DataListener not properly computed #7

Open chriswiesner opened 6 years ago

chriswiesner commented 6 years ago

I'm sending data on the mobile through

rxWear.data().putDataMap().to("/myPath")

which seems to properly create the Uri and results in wear://<nodeId>/myPath

but on the wear I listen like:

rxWear.data().listen("/myPath", DataApi.FILTER_LITERAL)

which gives me: wear:/myPath

In your Implementation you create the Uri with a Uri.Builder but do not set the host (which is missing in the above uri)

This bug results has the problem that the listen command is triggered by EVERY data-update, no matter of the specified Uri, see https://developers.google.com/android/reference/com/google/android/gms/wearable/DataClient.html#addListener(com.google.android.gms.wearable.DataClient.OnDataChangedListener,%20android.net.Uri,%20int)

istvangal commented 6 years ago

Hi,

I ran into the same "issue" and figured out I didn't use the proper filter when getting or listening to data or messages.

For data, use:

rxWear.data().get(path).compose(DataItemGetDataMap.filterByPath(path)),
rxWear.data().listen(path, DataApi.FILTER_LITERAL).compose(DataEventGetDataMap.filterByPathAndType(path, DataEvent.TYPE_CHANGED))

Note the filterByPath and filterByPathAndType parts. The original examples are with .nofilter(), that's why you get notified for any data update.

Same goes for messages, use MessageEventGetDataMap.filterByPath(path) if it's needed.

Cheers!