简体   繁体   中英

PutDataMapRequest object in Android Wear Data Layer

I'm developing android wear application by connecting to web services. I'm following the tutorial in this link ( https://www.sitepoint.com/connecting-to-web-services-with-android-wear/ ) and this is my first experience.

In this example, he has created a new putdatamaprequest object as

PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/apiurl");

And the API used to retrieve information is

https://www.worldtides.info/api?heights⪫=34.057&lon=151.152&length=21600&step=21600&key=af967f62-eb62-4574-b75e-a9056859055e

In my example, I have locally created API using node js

http://localhost:3000/view

So, my PutDataMapRequest object would be the one below or something else?

PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/view"); 

Cany anyone please explain me what is the meaning of the above line and whether it is correct or not?

The PutDataMapRequest.create parameter can be any value you like. It's traditionally structured as a path (and gets used as one by the internal URI mechanism), so if you're transferring a lot of different data items, it can be helpful to give them all meaningful paths to structure your data transfer. Also, any data item you put into the data layer will replace anything it already has at the same path, so if you are transferring multiple data items, you do need use different path values.

So for example, if your external API was supplying weather data, you might put individual values into the data layer with calls like these:

PutDataMapRequest tempMap = PutDataMapRequest.create("/weather/temperature");
PutDataMapRequest humidMap = PutDataMapRequest.create("/weather/humidity");
PutDataMapRequest windMap = PutDataMapRequest.create("/weather/wind_speed");

...and then you'd put the actual weather data into each of those fields.

If your API is only ever returning a single value, there's probably no harm in calling create("/view") as you put in your question, but generally you will want a more meaningful path than that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM